Building project involving cmake, how do I make it aware of libraries - cross-platform

When I try to build this project with cmake and gcc on a 64-bit linux (debian) machine, I get an error from the linker:
Linking C executable ../../../../cpsadamsx
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlopen'
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlclose'
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlerror'
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlsym'
collect2: ld returned 1 exit status
make[2]: *** [cpsadamsx] Error 1
make[1]: *** [sundials/examples/cpodes/serial/CMakeFiles/cpsadamsx.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Apparently dlopen, dlclose, dlerror and dlsym are references to libdl.so. I have that library in /lib64/libdl.so.2, but why is it not found?
Would it have been a normal './configure; make; make install'-path I could have set the LIBS variable and issued the configure command like this (I think):
export LIBS=-ldl && ./configure
But how do I do it now?
UPDATE:
So it seems that the (or at least a) library is found, but does not contain the symbols in question. Perhaps it tries with the 32-bit library in /lib?
Is there a way to disassemble /lib64/libdl.so.2 to make sure it does have the references dlopen etc?
The problem now seems to guide the build tools to the correct version of the library.

As this question is showing up on google and both answers won't point to the correct solution here it is:
In your CMakeLists.txt add ${CMAKE_DL_LIBS} to link against idl.
It should look similar to this:
target_link_libraries(ExpandableTest
${CMAKE_DL_LIBS}
Expandable
ExpandableTestLibrary
)

Probably you need to add target_link_libraries() - see link text

Add this in CMakeLists.txt and it should work:
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ldl")

Related

undefined reference to '__objc_class_name_...'

I am building an executable (GNUstep).
It depends on a libLibname.a static lib.
In the GNUmakefile of the executable I am linking libLibname.a like this:
executableToolName_LDFLAGS = /usr/GNUstep/Local/Library/Libraries/libLibname.a
It claims to link without errors:
Linking tool executableToolName ...
Problem: It seems to not find the symbols:
main.m:29: error: undefined reference to '._OBJC_REF_CLASS_SomeClassNameOfLibLibname'
..._LDFLAGSis only for libray targets.
For tool targets, linked libs must be listed in ADDITIONAL_OBJC_LIBS, prefixed with -l

Adding a dll to CMake

I am trying to add an external library, called OpenAlpr, with alpr.h and openalpr.lib/openalpr.dll files to my CLion project. I put the header file in my project directory and included it in the source code, but I have no idea how to add the .dll or .lib files. I looked at other answers like this and this, but they are too confusing for me and I could not get mine to work; the following errors are output when I try to run:
undefined reference to `alpr::Alpr::Alpr(std::string, std::string, std::string)'
.text+0x9f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `alpr::Alpr::Alpr(std::string, std::string, st
undefined reference to `alpr::Alpr::getVersion()'
(.text+0xf3): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `alpr::Alpr::getVersion()'
undefined reference to `alpr::Alpr::~Alpr()'
.text+0x123): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `alpr::Alpr::~Alpr()'
undefined reference to `alpr::Alpr::~Alpr()'
.text+0x1af): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `alpr::Alpr::~Alpr()'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/AlprCpp.dir/build.make:84: AlprCpp.exe] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/AlprCpp.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/AlprCpp.dir/rule] Error 2
make: *** [Makefile:118: AlprCpp] Error 2
These are the contents of my CMake file:
cmake_minimum_required(VERSION 3.12)
project(AlprCpp)
set(CMAKE_CXX_STANDARD 14)
add_executable(AlprCpp main.cpp alpr.h)
link_directories(C:\\Projects\\AlprCpp)
find_library(AlprCpp openalpr.lib)
Thanks in advance.
Do not copy the header files of your libraries to your project.
At some point you will need to go through tutorials the hard way and learn how to use find_package. If you just want to get thing to work quickly, here is one simplistic way (assuming file names Alpr.lib Alpr.h) .
cmake_minimum_required(VERSION 3.12)
project(AlprCpp)
set(ALPR_LIBRARY "" CACHE FILEPATH "Full path to Alpr.lib")
set(ALPR_INCLUDE_PATH "" CACHE PATH "Directory containing Alpr.h")
include_directories(${ALPR_INCLUDE_PATH})
add_executable(AlprCpp main.cpp)
target_link_libraries(AlprCpp ${ALPR_LIBRARY })
As for the dll files (assuming Windows), either set the PATH environment variable or copy the DLL to the directory where the .exe is located.

ld: library not found for -lopencv_imgproc error

While building my project, I am getting this error.
ld: library not found for -lopencv_imgproc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What kind of library it is.? Can somebody explain.
Hello friend there are a lot of reason of linkers error. Some basic reason:
1. You can remove linker error goto Build Setting>Build Active Architecture Only set to No for Target and Project both.
2. Sometimes unnecessary .a files created Target>General. Delete irrelevant .a files.
3. Delete all library paths from Build Setting>Search Paths(o top) which you are not using like AFNetworking then pls delete -lAFNetworking path.
Try this if still you got the error show me the screenshot.
Thanks

GNU Fortran cannot find library file although its physically there

I am trying to link a precompiled BLAS dll to a Fortran example, the linker refuses.
I read:
gfortran can't find library that IS there unfortunately what helped there didn't work for me.
Specifically:
gfortran -o "Test2" ./main.o -l"C:/Users/abc/workspace/Test2/blasdyndbgx64.dll"
c:/Program Files (x86)/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lC:/Users/abc/workspace/Test2/blasdyndbgx64.dll
collect2.exe: error: ld returned 1 exit status
make: *** [Test2] Error 1
The previous link I provided recommended to use the -l"entire/path/filename.ext", yet it still throws at me that error whatever I try. Obviously the file is there,
dir to the path+filename finds the dll.
I guess that since compilers are not my strong side I am still missing something trivial.

Unrecognized option "--enable-new-dtags" error during building c++ library

During building a c++ source code (configured with cmake gui) with mingw under MSYS gives following error while trying to "Linking C shared library":
Unrecognized option "--enable-new-dtags"
How can i solve this issue?
Likely --enable-new-dtags is supported only on ELF targets. For example there's a patch for Python3 distutils which sets this flag conditionally on the target platform: https://github.com/Alexpux/MINGW-packages/blob/master/mingw-w64-python3/0260-MINGW-compiler-enable-new-dtags.patch . You should make sure that this flag isn't specified explicitly somewhere in your project.