Reputation: 541
I'm trying to use NTL library for ZZ class, and would like to use dedicated functions. Unfortunately during compilation I'm getting a lot of errors:
[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**)'
I have installed libntl-dev on my linux mint, added set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -lntl" )
to my CMakeLists.txt
and set CMake option -lntl
and it has no effect. How can I link this library?
My CMakeLists.txt contains:
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)
Upvotes: 1
Views: 10296
Reputation: 1193
If you want to link to a runtime library using CMake, you need to use target_link_libraries command. For example, you may change your CMakeLists.txt file as follows:
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)
This is assuming CMake is able to find the NTL library in your system.
EDIT : Fix executable name typo.
Upvotes: 6