I am building project using some libraries and CMake.
There are two projects; first is library using *.so" file and second is library and executable based on the first.
But when I run executable file of second project,
I get the following error:
my_library: error while loading shared libraries: my_lib.so.0: cannot open shared object file: No such file or directory
CMakeLists.txt of FirstProject:
add_library(my_lib SHARED IMPORTED)
set_property(TARGET my_lib PROPERTY IMPORTED_LOCATION lib/my_lib/my_lib.so)
add_library(my_first_lib SHARED my_first_lib.cpp)
target_link_libraries(my_first_lib my_lib)
CMakeLists.txt of SecondProject:
add_library(my_second_lib my_second_lib.cpp)
target_link_libraries(my_second_lib ${my_first_lib_LIBRARIES})
add_executable(my_second_exe my_second_exe.cpp)
target_link_libraries(my_second_exe my_second_lib)
How to link "*.so" file properly?
Related
I want to create a shared *.dll library using a *.a Static library
Below is my CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(Projects)
set(CMAKE_CXX_STANDARD 11)
include_directories(../msys64/mingw64/include)
include_directories("../Program Files/Java/jdk1.8.0_151/include" "../Program Files/Java/jdk1.8.0_151/include/win32")
add_library(Projects1 SHARED main.cpp HelloWorld.cpp )
add_library(libgdal STATIC IMPORTED)
set_target_properties(libgdal PROPERTIES IMPORTED_LOCATION ../msys64/mingw64/lib/libgdal.a)
target_link_libraries(Projects1 A libgdal C )
it gives me below error:
*** No rule to make target '../msys64/mingw64/lib/libgdal.a', needed by 'libProjects1.dll'. Stop.
although when I try to create a Static Lib changing as below it works fine.
add_library(Projects1 STATIC main.cpp HelloWorld.cpp )
I am not sure how to create a Shared Library using a Static Library
Thanks for all the help in advance
i download opencv 3.1.0 and build it with cmake i unchecked BUILD_SHARED_LIBS
after building finish i try to compile an c++ code as static lib and this is my
CMakeListed.txt file
cmake_minimum_required(VERSION 2.8)
PROJECT(word)
set(OpenCV_DIR "/home/medozeus/videos/opencv/share/opencv")
FIND_PACKAGE( OpenCV REQUIRED )
INCLUDE_DIRECTORIES( ${OpenCV_INCLUDE_DIRS} )
ADD_EXECUTABLE(wordx main.cpp)
TARGET_LINK_LIBRARIES (wordx ${OpenCV_LIBS})
its compiled without error and i run the program also without error but when i send the program to another pc and run it its give me
error while loading shared libraries: libjpeg.so.8: cannot open shared object file: No such file or directory
this is my 3rdparty folder content after build
and the lib inside 3rdparty content
but the source code have all the library i don't know why when i build it only build one library in 3rdparty mabye this cause the error
error while loading shared libraries: libjpeg.so.8: cannot open shared object file: No such file or directory
this is my 3rdparty folder content in source code of open cv
any idea
The error means there is no libjpeg.so.8 file on target machine you are running your executable. You could try installing it:
sudo apt-get install libjpeg-dev
I cannot figure out why the library cannot be linked into my project, any help will be appreciated.
Background: The external library provides a list of header files and library files and are put in a directory named "dll", files including "Elveflow64.aliases","Elveflow64.dll","Elveflow64.ini","Elveflow64.lib""Elveflow64.h","*.h","lvanlys.dll".
The codes I use in the CMakeLists file are shown as bellow:
SET("LIB_Elveflow_DIR" ${CMAKE_CURRENT_SOURCE_DIR}/dll)
include_directories(${LIB_Elveflow_DIR})
add_library(Elveflow64 SHARED IMPORTED) #${LIB_Elveflow_DIR}//Elveflow64.lib
set_property(TARGET Elveflow64 PROPERTY IMPORTED_LOCATION ${LIB_Elveflow_DIR}/Elveflow64.dll)
set_property(TARGET Elveflow64 PROPERTY IMPORTED_IMPLIB ${LIB_Elveflow_DIR}/Elveflow64.lib)
set_property(TARGET Elveflow64 PROPERTY IMPORTED_LINK_DEPENDENT_LIBRARIES ${LIB_Elveflow_DIR}/lvanlys.dll)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} Elveflow64)
However, when I run the code, The program has unexpectedly finished as Elveflow64.dll is missing.
On Ubuntu, I have two directories: build and src. In src, my CMakeLists.txt file has the lines:
add_executable(Test main.cpp)
target_link_libraries(Test libCamera.so)
After running cmake in the build directory (cmake ../src), I then copy my library file libCamera.so into the build directory. After running make, the main.cpp.o file compiles successfully, but I receive the following error during linking:
/usr/bin/ld: cannot find -lCamera
Why is this? The shared library is in the same directory that I am building in... and the same thing happens if I copy the library to /usr/bin...
You should not put prefix lib and suffix .so of the library, so just use:
target_link_libraries(Test Camera)
if your library not found you may need to add directory, where library is located:
link_directories( /home/user/blah ) # for specific path
link_directories( ${CMAKE_CURRENT_BINARY_DIR} ) # if you put library where binary is generated
Note: you copied lib to /usr/bin but unlike Windows where dll files stored with executables, in Linux that is not the case, so it would be /usr/lib, not /usr/bin. Also you may change LD_LIBRARY_PATH variable to make your program to find a library in a custom location.
I have linked an external c++-library to an existing cmake project using the following cmake commands:
SET (some_src
.
.(sourcefiles here)
.
.
.
.
)
ADD_LIBRARY(some_proj SHARED ${some_src})
# Adding precompiled NURBS lib
SET(nurbs_libs ${CMAKE_SOURCE_DIR}/src/nurbs/libs)
ADD_LIBRARY( nurbs_C SHARED IMPORTED )
SET_TARGET_PROPERTIES( nurbs_C PROPERTIES
IMPORTED_LOCATION ${nurbs_libs}/surface.so.1.0
LINKER_LANGUAGE "CXX")
TARGET_LINK_LIBRARIES( some_proj nurbs_C )
SET(CMAKE_INSTALL_PATH ${nurbs_libs})
INSTALL(TARGETS some_proj DESTINATION lib)
install(FILES ${nurbs_libs}/surface.so.1.0 DESTINATION lib)
When trying to run a program that uses the library I keep getting the error
reels: error while loading shared libraries:
surface.so.1: cannot open shared object file: No such file or directory
I tried playing with LD_LIBRARY_PATH and RPATH but to no avail. I suspect I did something wrong with the cmake file. How can I handle this problem?
Because you have binary file compiled, there is probably no problem with your CMakeLists.txt. Use ldd to find out which libraries you are missing. Also check that you have surface.so.1 present on disk (probably it would be link directing to surface.so.1.0)