I am having trouble linking python 3 in cmake.
The options to link in the shell are $(/usr/bin/python3-config --ldflags) and that works completely fine.
But when I move to cmake, I use:
set(Python_ADDITIONAL_VERSIONS 3.5)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(sim ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(sim ${CMAKE_DL_LIBS})
target_link_libraries(sim ${PYTHON_LIBRARIES})
giving me the error:
/usr/bin/ld: /usr/local/lib/libpython3.5m.a(dynload_shlib.o): undefined reference to symbol 'dlsym##GLIBC_2.2.5'
/usr/lib/x86_64-linux-gnu/libdl.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I then tried
target_link_libraries(sim "$(/usr/bin/python3-config --ldflags)")
but this also does not work with error message
c++: error: $(/usr/bin/python3-config: No such file or directory
c++: error: unrecognized command line option ‘--ldflags)’
The only method that works for me is to open the subshell by
echo $(/usr/bin/python3-config --ldflags)
-L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -L/usr/lib -lpython3.5m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions
and write the content to cmake as
target_link_libraries(sim "-L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -L/usr/lib -lpython3.5m -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions")
This works but the method is nasty. Is there any clean way to perform such linking?
Related
I am trying to build a very simple cuda example with CMake. The example calls the cudaGetDeviceCount function. I learnt from another post that I need to link it with the cudart library. I'm getting this error:
Found CUDA installation: /usr/local/cuda, version unknown
"/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o testcuda /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crt1.o /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/crtbegin.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../.. -L/usr/lib/llvm-6.0/bin/../lib -L/lib -L/usr/lib CMakeFiles/testcuda.dir/main.cpp.o -lcuda -lcudart -L/usr/local/cuda/lib64/stubs -L. -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/crtend.o /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../x86_64-linux-gnu/crtn.o
/usr/bin/ld: cannot find -lcudart
Here is my CMakeLists.txt.
cmake_minimum_required(VERSION 3.15)
project (testcuda CXX CUDA)
if (NOT DEFINED CMAKE_CXX_STANDARD)
set (CMAKE_CXX_STANDARD_17)
set (CMAKE_CXX_STANDARD_REQUIRED True)
endif()
if (NOT DEFINED CMAKE_CUDA_STANDARD)
set (CMAKE_CUDA_STANDARD_17)
set (CMAKE_CUDA_STANDARD_REQUIRED True)
endif()
set (CMAKE_EXE_LINKER_FLAGS -v)
add_executable (testcuda main.cpp)
target_include_directories(testcuda PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
target_link_libraries(testcuda cuda cudart)
MESSAGE (STATUS ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
MESSAGE (STATUS ${CUDA_LIBRARIES})
MESSAGE (STATUS ${CUDA_VERSION})
The location of my libcudart is here:
/usr/local/cuda-10.1/targets/x86_64-linux/lib/libcudart.so
The output of variable CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES is /usr/local/cuda/targets/x86_64-linux/include, but both CUDA_LIBRARIES and CUDA_VERSION are empty.
My CMake is 3.15.
Have I missed anything?
When you use CUDA first-class language support with cmake it expects you to name any CUDA-relevant files with a .cu extension. Rename main.cpp to main.cu
Are you even using cudart? You shouldn't need it for a simple cudaGetDeviceCount call.
That said, that version unknown line is concerning. Normally /usr/local/cuda is a symbolic link, what does that point to? Check to make sure that it's pointing to cuda-10.1. If that's okay then you may want to reinstall the CUDA Toolkit
I'm trying to use libcinder to make some visualizations. In integrating in my existing codebase, I've run into some linker errors that I can't figure out.
I've boiled the problem down to a minimal example, with the following results:
cd /build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/BasicApp.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/BasicApp.dir/BasicApp.cpp.o -o ../bin/BasicApp -rdynamic -lPocoUtil -lPocoFoundation
make[2]: Leaving directory '/build'
[100%] Built target BasicApp
make[1]: Leaving directory '/build'
/usr/bin/cmake -E cmake_progress_start /build/CMakeFiles 0
If don't involve cinder at all, everything works fine, as seen above. if I add my function to the minimal cinder example (BasicApp), I get the following output on compilation:
cd /build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/BasicApp.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/BasicApp.dir/BasicApp.cpp.o -o ../bin/BasicApp -rdynamic -lPocoUtil -lPocoFoundation /cinder/lib/linux/x86_64/ogl/Release/libcinder.a -lGLU -lGL -lSM -lICE -lX11 -lXext -lXcursor -lXinerama -lXrandr -lXi -lz -lcurl -lfontconfig -lpulse -lmpg123 -lsndfile -lgobject-2.0 -lglib-2.0 -lgstreamer-1.0 -lgstbase-1.0 -lgstapp-1.0 -lgstvideo-1.0 -lgstgl-1.0 /cinder/lib/linux/x86_64//libboost_system.a /cinder/lib/linux/x86_64//libboost_filesystem.a -ldl -lpthread
CMakeFiles/BasicApp.dir/BasicApp.cpp.o: In function `load_images(std::string, std::string, int, int)':
BasicApp.cpp:(.text+0xca2): undefined reference to `Poco::DirectoryIterator::DirectoryIterator(std::string const&)'
BasicApp.cpp:(.text+0xd57): undefined reference to `Poco::DirectoryIterator::DirectoryIterator(std::string const&)'
collect2: error: ld returned 1 exit status
src/CMakeFiles/BasicApp.dir/build.make:118: recipe for target 'bin/BasicApp' failed
make[2]: *** [bin/BasicApp] Error 1
make[2]: Leaving directory '/build'
CMakeFiles/Makefile2:1244: recipe for target 'src/CMakeFiles/BasicApp.dir/all' failed
make[1]: *** [src/CMakeFiles/BasicApp.dir/all] Error 2
make[1]: Leaving directory '/build'
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
I'm assuming that some configuration set in the cinder cmake files is messing things up, but I don't understand why or how to fix it.
This is with gcc version 5.4.0 and cmake version 3.5.1.
Here is a reduced cmake file that has this issue:
cmake_minimum_required(VERSION 3.2)
project(segslam C CXX)
set(CMAKE_CXX_STANDARD 11)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/poco")
find_package(Poco REQUIRED)
#include($ENV{CINDER_PATH}/proj/cmake/configure.cmake)
#set(cinder_DIR $ENV{CINDER_PATH}/${CINDER_LIB_DIRECTORY})
#find_package(cinder REQUIRED PATHS " $ENV{CINDER_PATH}/${CINDER_LIB_DIRECTORY}")
add_executable(BasicApp BasicApp.cpp)
#target_include_directories(BasicApp PUBLIC $ENV{CINDER_PATH}/include)
#target_link_libraries(BasicApp cinder)
target_link_libraries(BasicApp ${Poco_LIBRARIES})
set_target_properties(BasicApp PROPERTIES
DEBUG_POSTFIX "d"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
install(TARGETS BasicApp RUNTIME DESTINATION bin COMPONENT main)
install(FILES ${srcs} DESTINATION app COMPONENT main)
If the commented lines are uncommented, it links in cinder and things break. I'm using a FindPoco.cmake file from here. The cinder cmake files are located here.
It doesn't seem to matter what the linking order is, and none of the other libraries I'm using have this issue.
So it turns out that the issue is an ABI mismatch. Cinder ships with precompiled boost libraries that use a gcc version <5.1, which will cause conflicts if you try to use libraries that have been compiled with gcc version >= 5.1.
My fix was to remove the cinder precompiled boost libraries and recompile with the version of boost in the ubuntu repos.
See this thread on the cinder discourse for more info.
I'm new about RInside and I want to run the examples about QT
I get this error all the time I use "qmake" and "make" as say the README, and I really want to know what can I do about it.
$ g++ -Wl,-O1 -o qtdensity qtdensity.o main.o moc_qtdensity.o -L/usr/lib/i386-linux-gnu -Wl,--export-dynamic -fopenmp -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lrt -ldl -lm -lblas -llapack -L/home/user/R/i686-pc-linux-gnu-library/3.1/RInside/lib -lRInside -Wl,-rpath,/home/user/R/i686-pc-linux-gnu-library/3.1/RInside/lib -lQtSvg -lQtGui -lQtCore -lpthread
/usr/bin/ld: cannot find -llzma
collect2: ld devolvió el estado de salida 1
make: *** [qtdensity] Error 1
I thought it was because I had not the library lzma, but I intalled it and I still get the same error.
What can I do? Can you help me please?
when I open a terminal, switch to my project directory (which is in my home folder) and run the command "wmake" I get the error:
g++ -m32 -Dlinux -DWM_DP -Wall -Wextra -Wno-unused-parameter
-Wold-style-cast -O3 -DNoRepository -ftemplate-depth-100 -IphaseModel/lnInclude -ImultiphaseSystem/lnInclude -ImultiphaseFixedFluxPressure -IinterfacialModels/lnInclude -I/opt/openfoam221/src/transportModels -I/opt/openfoam221/src/transportModels/incompressible/lnInclude -I/opt/openfoam221/src/transportModels/interfaceProperties/lnInclude -I/opt/openfoam221/src/transportModels/incompressible/lnInclude -I/opt/openfoam221/src/transportModels/incompressible/singlePhaseTransportModel
-I/opt/openfoam221/src/turbulenceModels -I/opt/openfoam221/src/turbulenceModels/incompressible/LES/LESModel -I/opt/openfoam221/src/turbulenceModels/LES/LESdeltas/lnInclude -I/opt/openfoam221/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/openfoam221/src/OpenFOAM/lnInclude -I/opt/openfoam221/src/OSspecific/POSIX/lnInclude -fPIC -Xlinker --add-needed -Xlinker --no-as-needed Make/linuxGccDPOpt/multiphaseEulerFoam.o
-L/opt/openfoam221/platforms/linuxGccDPOpt/lib \
-lmultiphaseSystem -lcompressibleMultiPhaseModel -linterfaceProperties -lincompressibleTransportModels -lcompressibleMultiphaseEulerianInterfacialModels -lincompressibleLESModels -lincompressibleRASModels -lfiniteVolume -lOpenFOAM -ldl -lm -o /opt/openfoam221/platforms/linuxGccDPOpt/bin/multiphaseEulerFoam /usr/bin/ld: cannot open output file /opt/openfoam221/platforms/linuxGccDPOpt/bin/multiphaseEulerFoam: Permission denied collect2: ld returned 1 exit status make: * [/opt/openfoam221/platforms/linuxGccDPOpt/bin/multiphaseEulerFoam] Error 1
This error occured the first time today, yesterday everything compiled fine for me.
How can I fix this?
I am trying to build a project using Boost's Asio , but I am getting linking error:
g++ -o homework main.o -L/usr/lib64/qt-3.3/lib -L/usr/X11R6/lib64 -L/home/student/boost_1_46_1/libs -lboost_system -lqt-mt -lXext -lX11 -lm
/usr/bin/ld: cannot find -lboost_system
collect2: ld returned 1 exit status
make: *** [homework] Error 1
How can I resolve the problem?
I think it's a typo. You said -l boost_system in command line, while it should be -lboost_system.
Update:
Nope! I get my answer back. Just found that it's OK to pass -l <libname>. In fact it's equal to -l<libname>. As others said, double-check paths.