我正在尝试为ZZ类使用NTL库,并且希望使用专用函数。不幸的是,在编译过程中,我遇到了很多错误:
[100%] Linking CXX executable hpc5
CMakeFiles/hpc5.dir/main.cpp.o: In function `findX(NTL::ZZ, NTL::ZZ, NTL::ZZ)':
/home/rooter/CLionProjects/hpc5/main.cpp:44: undefined reference to `find_xi(NTL::ZZ, NTL::ZZ)'
/home/rooter/CLionProjects/hpc5/main.cpp:57: undefined reference to `chinese_remainder(NTL::ZZ*, NTL::ZZ*, NTL::ZZ)'
/home/rooter/CLionProjects/hpc5/main.cpp:58: undefined reference to `NTL::operator<<(std::ostream&, NTL::ZZ const&)'
CMakeFiles/hpc5.dir/main.cpp.o: In function `NTL::ZZ::ZZ(NTL::ZZ const&)':
/usr/include/NTL/ZZ.h:58: undefined reference to `_ntl_gcopy(void*, void**)'
CMakeFiles/hpc5.dir/main.cpp.o: In function `NTL::ZZ::operator=(NTL::ZZ const&)':
/usr/include/NTL/ZZ.h:73: undefined reference to `_ntl_gcopy(void*, void**)'
CMakeFiles/hpc5.dir/main.cpp.o: In function `NTL::ZZ::operator=(long)':
/usr/include/NTL/ZZ.h:75: undefined reference to `_ntl_gintoz(long, void**)'我在我的linux薄荷上安装了libntl-dev,将set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -lntl" )添加到我的CMakeLists.txt中,并设置了CMake选项-lntl,但没有任何效果。我如何连接这个图书馆?
我的CMakeLists.txt包含:
cmake_minimum_required(VERSION 3.10)
project(hpc5)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -lntl" )
add_executable(hpc5 main.cpp)发布于 2018-05-16 09:07:14
如果要使用CMake链接到运行时库,则需要使用库命令。例如,您可以按以下方式更改CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.10)
project(hpc5)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" )
add_executable(hpc5 main.cpp)
target_link_libraries(hpc5 ntl)这是假设CMake能够在您的系统中找到NTL库。
编辑:修正可执行名称错误。
https://stackoverflow.com/questions/50365936
复制相似问题