CMake OS X CLion. How to link a custom dynamic library? - c++

Probably this question was asked several times. But I can't find a solution. I try to link a shared library and add it to RPATH. I tried several solutions:
Here is my Cmake file:
cmake_minimum_required(VERSION 3.7)
project(Cpp)
set(CMAKE_CXX_STANDARD 11)
file(GLOB CPP_UTILS CppUtils/*.cpp CppUtils/*.h)
set(SOURCE_FILES main.cpp ${CPP_UTILS})
add_executable(Cpp ${SOURCE_FILES})
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
target_link_libraries(Cpp /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/libs/libpython3.7m.dylib)
include_directories(Include)
And it outputs the following error in runtime:
dyld: Library not loaded: /usr/local/lib/libpython3.7m.dylib
Referenced from: /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug/Cpp
Reason: image not found
Temporary I just want link a custom library, to understand how it works. Then I want to copy the libs folder while build execution.
This is what it outputs when I try to run the command manually make VERBOSE=1
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H/Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp -B/Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug/CMakeFiles /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Cpp.dir/build.make CMakeFiles/Cpp.dir/depend
cd /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug/CMakeFiles/Cpp.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Cpp.dir/build.make CMakeFiles/Cpp.dir/build
make[2]: Nothing to be done for `CMakeFiles/Cpp.dir/build'.
[100%] Built target Cpp
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug/CMakeFiles 0
yo:cmake-build-debug stikhonenko$ make clean
yo:cmake-build-debug stikhonenko$ make VERBOSE=1
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H/Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp -B/Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug/CMakeFiles /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Cpp.dir/build.make CMakeFiles/Cpp.dir/depend
cd /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug/CMakeFiles/Cpp.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Cpp.dir/build.make CMakeFiles/Cpp.dir/build
[ 25%] Building CXX object CMakeFiles/Cpp.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -I/Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/Include -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -std=gnu++11 -o CMakeFiles/Cpp.dir/main.cpp.o -c /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/main.cpp
[ 50%] Building CXX object CMakeFiles/Cpp.dir/CppUtils/System.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -I/Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/Include -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -std=gnu++11 -o CMakeFiles/Cpp.dir/CppUtils/System.cpp.o -c /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/CppUtils/System.cpp
[ 75%] Building CXX object CMakeFiles/Cpp.dir/CppUtils/TimeUtils.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -I/Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/Include -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -std=gnu++11 -o CMakeFiles/Cpp.dir/CppUtils/TimeUtils.cpp.o -c /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/CppUtils/TimeUtils.cpp
[100%] Linking CXX executable Cpp
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/Cpp.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/Cpp.dir/main.cpp.o CMakeFiles/Cpp.dir/CppUtils/System.cpp.o CMakeFiles/Cpp.dir/CppUtils/TimeUtils.cpp.o -o Cpp ../libs/libpython3.7m.dylib
[100%] Built target Cpp
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start /Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/cmake-build-debug/CMakeFiles 0

You first need to tell cmake where to find the library (find_library), and only then you can use the result from find_library in target_link_libraries
find_library takes a PATHS argument which you can use to tell cmake where to look
find_library(
PYTHON_3
libpython3.7m
PATHS
/Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/libs)
Now you will have a variable ${PYTHON_3} which contains the path to the library. You use that variable in target_link_libraries
target_link_libraries(
Cpp
${PYTHON_3})
Here is the complete CMakeLists.txt:
cmake_minimum_required(VERSION 3.7)
project(Cpp)
set(CMAKE_CXX_STANDARD 11)
file(GLOB CPP_UTILS CppUtils/*.cpp CppUtils/*.h)
set(SOURCE_FILES main.cpp ${CPP_UTILS})
add_executable(Cpp ${SOURCE_FILES})
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
find_library(
PYTHON_3
libpython3.7m
PATHS
/Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/libs)
target_link_libraries(Cpp ${PYTHON_3})
target_include_directories(Cpp Include)

Lets try linking the library's directory!
Assuming the name of your library is libpython3
cmake_minimum_required(VERSION 3.7)
project(Cpp)
set(CMAKE_CXX_STANDARD 11)
file(GLOB CPP_UTILS CppUtils/*.cpp CppUtils/*.h)
set(SOURCE_FILES main.cpp ${CPP_UTILS})
add_executable(Cpp ${SOURCE_FILES})
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
LINK_DIRECTORIES(/Users/mac/Projects/ECMCalmnessScroreAlgo/Cpp/libs)
target_link_libraries(Cpp libpython3.7m)
include_directories(Include)
Does this work? :-)

Related

How to link with binary using mingw32 in wine

I have made this minimal project to reproduce my link problem using mingw32 in wine32:
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project("tst" VERSION 1.1.0)
add_executable("tst" "main.cpp")
add_library("resource" "text.o")
set_target_properties("resource" PROPERTIES LINKER_LANGUAGE CXX)
add_custom_command(OUTPUT "text.o"
MAIN_DEPENDENCY "text"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/text" "text"
COMMAND ${CMAKE_LINKER} -r -b binary "text" -o "text.o"
)
set_source_files_properties("text" PROPERTIES GENERATED true EXTERNAL_OBJECT true)
target_link_libraries("tst" "resource")
main.cpp
#include <iostream>
#include <string>
extern char _binary_text_start[];
extern char _binary_text_end[];
int main()
{
std::string text{ _binary_text_start, _binary_text_end };
std::cout << text << std::endl;
}
text
Hello, World!
This project builds and runs using mingw-w64 on Linux; however, when I try to build the project in wine32, I got this output:
Z:\cmake-3.19.1-win32-x86\bin\cmake.exe -SZ:\var\cache\deploy\cpp -BZ:\var\cache\deploy\cpp\build\windows --check-build-system CMakeFiles\Makefile.cmake 0
Z:\cmake-3.19.1-win32-x86\bin\cmake.exe -E cmake_progress_start Z:\var\cache\deploy\cpp\build\windows\CMakeFiles Z:\var\cache\deploy\cpp\build\windows\\CMakeFiles\progress.marks
mingw32-make -f CMakeFiles\Makefile2 all
mingw32-make[1]: Entering directory `Z:/var/cache/deploy/cpp/build/windows'
mingw32-make -f CMakeFiles\resource.dir\build.make CMakeFiles/resource.dir/depend
mingw32-make[2]: Entering directory `Z:/var/cache/deploy/cpp/build/windows'
[ 25%] Generating text.o
Z:\cmake-3.19.1-win32-x86\bin\cmake.exe -E copy Z:/var/cache/deploy/cpp/text text
Z:\mingw32\bin\ld.exe -r -b binary text -o text.o
Z:\cmake-3.19.1-win32-x86\bin\cmake.exe -E cmake_depends "MinGW Makefiles" Z:\var\cache\deploy\cpp Z:\var\cache\deploy\cpp Z:\var\cache\deploy\cpp\build\windows Z:\var\cache\deploy\cpp\build\windows Z:\var\cache\deploy\cpp\build\windows\CMakeFiles\resource.dir\DependInfo.cmake --color=
mingw32-make[2]: Leaving directory `Z:/var/cache/deploy/cpp/build/windows'
mingw32-make -f CMakeFiles\resource.dir\build.make CMakeFiles/resource.dir/build
mingw32-make[2]: Entering directory `Z:/var/cache/deploy/cpp/build/windows'
[ 50%] Linking CXX static library libresource.a
Z:\cmake-3.19.1-win32-x86\bin\cmake.exe -P CMakeFiles\resource.dir\cmake_clean_target.cmake
Z:\cmake-3.19.1-win32-x86\bin\cmake.exe -E cmake_link_script CMakeFiles\resource.dir\link.txt --verbose=1
Z:\mingw32\bin\ar.exe qc libresource.a text.o
Z:\mingw32\bin\ranlib.exe libresource.a
mingw32-make[2]: Leaving directory `Z:/var/cache/deploy/cpp/build/windows'
[ 50%] Built target resource
mingw32-make -f CMakeFiles\tst.dir\build.make CMakeFiles/tst.dir/depend
mingw32-make[2]: Entering directory `Z:/var/cache/deploy/cpp/build/windows'
Z:\cmake-3.19.1-win32-x86\bin\cmake.exe -E cmake_depends "MinGW Makefiles" Z:\var\cache\deploy\cpp Z:\var\cache\deploy\cpp Z:\var\cache\deploy\cpp\build\windows Z:\var\cache\deploy\cpp\build\windows Z:\var\cache\deploy\cpp\build\windows\CMakeFiles\tst.dir\DependInfo.cmake --color=
mingw32-make[2]: Leaving directory `Z:/var/cache/deploy/cpp/build/windows'
mingw32-make -f CMakeFiles\tst.dir\build.make CMakeFiles/tst.dir/build
mingw32-make[2]: Entering directory `Z:/var/cache/deploy/cpp/build/windows'
[ 75%] Building CXX object CMakeFiles/tst.dir/main.cpp.obj
Z:\mingw32\bin\g++.exe -O3 -DNDEBUG -o CMakeFiles\tst.dir\main.cpp.obj -c Z:\var\cache\deploy\cpp\main.cpp
[100%] Linking CXX executable tst.exe
Z:\cmake-3.19.1-win32-x86\bin\cmake.exe -E cmake_link_script CMakeFiles\tst.dir\link.txt --verbose=1
Z:\cmake-3.19.1-win32-x86\bin\cmake.exe -E rm -f CMakeFiles\tst.dir/objects.a
Z:\mingw32\bin\ar.exe cr CMakeFiles\tst.dir/objects.a #CMakeFiles\tst.dir\objects1.rsp
Z:\mingw32\bin\g++.exe -O3 -DNDEBUG -Wl,--whole-archive CMakeFiles\tst.dir/objects.a -Wl,--no-whole-archive -o tst.exe -Wl,--out-implib,libtst.dll.a -Wl,--major-image-version,0,--minor-image-version,0 #CMakeFiles\tst.dir\linklibs.rsp
z:/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\tst.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x43): undefined reference to `_binary_text_end'
z:/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\tst.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x48): undefined reference to `_binary_text_start'
z:/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\tst.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x68): undefined reference to `_binary_text_start'
z:/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles\tst.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x16f): undefined reference to `_binary_text_start'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [tst.exe] Error 1
mingw32-make[2]: Leaving directory `Z:/var/cache/deploy/cpp/build/windows'
mingw32-make[1]: *** [CMakeFiles/tst.dir/all] Error 2
mingw32-make[1]: Leaving directory `Z:/var/cache/deploy/cpp/build/windows'
mingw32-make: *** [all] Error 2
nm libresource.a
text.o:
0000000d D _binary_text_end
0000000d A _binary_text_size
00000000 D _binary_text_start
objdump -f libresource.a
In archive libresource.a:
text.o: file format pe-i386
architecture: i386, flags 0x00000038:
HAS_DEBUG, HAS_SYMS, HAS_LOCALS
start address 0x00000000
cmake: https://github.com/Kitware/CMake/releases/download/v3.19.1/cmake-3.19.1-win32-x86.zip
mingw: https://pilotfiber.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/ray_linn/GCC-10.x-with-ada/mingw32-10.2.0-crt-8.0.0-with-ada.7z
mingw-make: https://phoenixnap.dl.sourceforge.net/project/mingw/MinGW/Extension/make/mingw32-make-3.80-3/mingw32-make-3.80.0-3.tar.gz

Why include paths are inherited even for private linking

I have simple project consisting of 2 "libraries" a and b and executable c. I set include path for library a (PUBLIC) to X (for testing purposes, there's actually no such path).
Now, b links privately with a and c links with b. I expect X not to be in include path when compiling c.cpp because "it should not know about a since it's in private in b" But apparently It's here.
So my question is it intended behaviour or not and why.
My code:
a.cpp
void a() {}
b.cpp
void b() {}
c.cpp
int main() {}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
add_library(a a.cpp)
target_include_directories(a PUBLIC X)
add_library(b b.cpp)
target_link_libraries(b PRIVATE a)
add_executable(c c.cpp)
target_link_libraries(c PUBLIC b)
(Verbose) Compilation log:
/usr/local/Cellar/cmake/3.8.1/bin/cmake -H/Users/alexeyd/test/dir -B/Users/alexeyd/test/dir/build --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 c
/usr/local/Cellar/cmake/3.8.1/bin/cmake -H/Users/alexeyd/test/dir -B/Users/alexeyd/test/dir/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.8.1/bin/cmake -E cmake_progress_start /Users/alexeyd/test/dir/build/CMakeFiles 6
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 CMakeFiles/c.dir/all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/a.dir/build.make CMakeFiles/a.dir/depend
cd /Users/alexeyd/test/dir/build && /usr/local/Cellar/cmake/3.8.1/bin/cmake -E cmake_depends "Unix Makefiles" /Users/alexeyd/test/dir /Users/alexeyd/test/dir /Users/alexeyd/test/dir/build /Users/alexeyd/test/dir/build /Users/alexeyd/test/dir/build/CMakeFiles/a.dir/DependInfo.cmake --color=
Dependee "/Users/alexeyd/test/dir/build/CMakeFiles/a.dir/DependInfo.cmake" is newer than depender "/Users/alexeyd/test/dir/build/CMakeFiles/a.dir/depend.internal".
Dependee "/Users/alexeyd/test/dir/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/alexeyd/test/dir/build/CMakeFiles/a.dir/depend.internal".
Scanning dependencies of target a
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/a.dir/build.make CMakeFiles/a.dir/build
[ 16%] Building CXX object CMakeFiles/a.dir/a.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -I/Users/alexeyd/test/dir/X -o CMakeFiles/a.dir/a.cpp.o -c /Users/alexeyd/test/dir/a.cpp
[ 33%] Linking CXX static library liba.a
/usr/local/Cellar/cmake/3.8.1/bin/cmake -P CMakeFiles/a.dir/cmake_clean_target.cmake
/usr/local/Cellar/cmake/3.8.1/bin/cmake -E cmake_link_script CMakeFiles/a.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar qc liba.a CMakeFiles/a.dir/a.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib liba.a
[ 33%] Built target a
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/b.dir/build.make CMakeFiles/b.dir/depend
cd /Users/alexeyd/test/dir/build && /usr/local/Cellar/cmake/3.8.1/bin/cmake -E cmake_depends "Unix Makefiles" /Users/alexeyd/test/dir /Users/alexeyd/test/dir /Users/alexeyd/test/dir/build /Users/alexeyd/test/dir/build /Users/alexeyd/test/dir/build/CMakeFiles/b.dir/DependInfo.cmake --color=
Dependee "/Users/alexeyd/test/dir/build/CMakeFiles/b.dir/DependInfo.cmake" is newer than depender "/Users/alexeyd/test/dir/build/CMakeFiles/b.dir/depend.internal".
Dependee "/Users/alexeyd/test/dir/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/alexeyd/test/dir/build/CMakeFiles/b.dir/depend.internal".
Scanning dependencies of target b
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/b.dir/build.make CMakeFiles/b.dir/build
[ 50%] Building CXX object CMakeFiles/b.dir/b.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -I/Users/alexeyd/test/dir/X -o CMakeFiles/b.dir/b.cpp.o -c /Users/alexeyd/test/dir/b.cpp
[ 66%] Linking CXX static library libb.a
/usr/local/Cellar/cmake/3.8.1/bin/cmake -P CMakeFiles/b.dir/cmake_clean_target.cmake
/usr/local/Cellar/cmake/3.8.1/bin/cmake -E cmake_link_script CMakeFiles/b.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar qc libb.a CMakeFiles/b.dir/b.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib libb.a
[ 66%] Built target b
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/c.dir/build.make CMakeFiles/c.dir/depend
cd /Users/alexeyd/test/dir/build && /usr/local/Cellar/cmake/3.8.1/bin/cmake -E cmake_depends "Unix Makefiles" /Users/alexeyd/test/dir /Users/alexeyd/test/dir /Users/alexeyd/test/dir/build /Users/alexeyd/test/dir/build /Users/alexeyd/test/dir/build/CMakeFiles/c.dir/DependInfo.cmake --color=
Dependee "/Users/alexeyd/test/dir/build/CMakeFiles/c.dir/DependInfo.cmake" is newer than depender "/Users/alexeyd/test/dir/build/CMakeFiles/c.dir/depend.internal".
Dependee "/Users/alexeyd/test/dir/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/alexeyd/test/dir/build/CMakeFiles/c.dir/depend.internal".
Scanning dependencies of target c
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/c.dir/build.make CMakeFiles/c.dir/build
[ 83%] Building CXX object CMakeFiles/c.dir/c.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -I/Users/alexeyd/test/dir/X -o CMakeFiles/c.dir/c.cpp.o -c /Users/alexeyd/test/dir/c.cpp
[100%] Linking CXX executable c
/usr/local/Cellar/cmake/3.8.1/bin/cmake -E cmake_link_script CMakeFiles/c.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/c.dir/c.cpp.o -o c libb.a liba.a
[100%] Built target c
/usr/local/Cellar/cmake/3.8.1/bin/cmake -E cmake_progress_start /Users/alexeyd/test/dir/build/CMakeFiles 0
Interesting part of log:
[ 83%] Building CXX object CMakeFiles/c.dir/c.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -I/Users/alexeyd/test/dir/X -o CMakeFiles/c.dir/c.cpp.o -c /Users/alexeyd/test/dir/c.cpp
I use CMake 3.8.1
The strange behavior does not appear if you specify a minimum CMake version >= 2.8.12:
cmake_minimum_required(VERSION 2.8.12)
target_include_directories and the PRIVATE/PUBLIC differentiation did not exist before CMake 2.8.12. My take is that with versions older than that CMake chooses to make everything PUBLIC by default.

cmake: adding C++ standard when not required

When building a C++ executable under Linux using cmake 3.7, I see a -std=gnu++11 flag being added to compile flags. The problem is, I'm already manually adding a -std=c++1z flag, and this new one overwrites mine. This happens only for executables, but I cannot find this being mentioned in the docs. The CMAKE_CXX_STANDARD is empty, and setting the CXX_STANDARD property on the target has no effect. Is there a way to remove this flag?
This seems to be not only limited to executables.
Here's my (simplified) cmake:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
find_boost(serialization system)
find_package(Qt5Widgets REQUIRED)
link_directories(${Boost_LIBRARY_DIRS})
include_directories(
${Boost_INCLUDE_DIRS}
${ZMQ_INCLUDE_DIR}
${CPPZMQ_INCLUDE_DIR}
)
if(WIN32)
add_definitions(-DNOMINMAX)
endif()
add_executable(
${PROFILER_CLIENT_NAME}
main.cpp
MainWindow.cpp
MainWindow.h
ProfilerWidget.cpp
ProfilerWidget.h
TimelineWidget.cpp
TimelineWidget.h
ZmqReceiver.cpp
ZmqReceiver.h
)
add_dependencies(${PROFILER_CLIENT_NAME} boost zeromq)
target_link_libraries(
${PROFILER_CLIENT_NAME}
PRIVATE ${PROFILER_NAME}
PRIVATE ${Boost_LIBRARIES}
PRIVATE Qt5::Widgets
)
As #florian suspected, it's Qt5 that's polluting your compile commands. Using a similar CMakeLists.txt:
cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
set(BOOST_ROOT "/usr/local/opt/boost#1.55")
execute_process(COMMAND brew --prefix qt5
COMMAND tr -d \\n
OUTPUT_VARIABLE QT5_BREW_PATH)
find_package(Boost COMPONENTS serialization system)
find_package(Qt5 COMPONENTS Widgets HINTS ${QT5_BREW_PATH})
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo main.cpp)
target_link_libraries(foo
PRIVATE ${Boost_LIBRARIES}
PRIVATE Qt5::Widgets
)
I configured and built a dummy executable. You can plainly see the -std=c++1z and the -std=gnu++11 on the compile line:
❯ make VERBOSE=1
/usr/local/Cellar/cmake/3.7.2/bin/cmake -H/Users/nega/foo -B/Users/nega/foo --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_progress_start /Users/nega/foo/CMakeFiles /Users/nega/foo/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/foo.dir/build.make CMakeFiles/foo.dir/depend
cd /Users/nega/foo && /usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_depends "Unix Makefiles" /Users/nega/foo /Users/nega/foo /Users/nega/foo /Users/nega/foo /Users/nega/foo/CMakeFiles/foo.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/foo.dir/build.make CMakeFiles/foo.dir/build
[ 50%] Building CXX object CMakeFiles/foo.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I/usr/local/opt/boost#1.55/include -iframework /usr/local/opt/qt5/lib -isystem /usr/local/opt/qt5/lib/QtWidgets.framework/Headers -isystem /usr/local/opt/qt5/lib/QtGui.framework/Headers -isystem /System/Library/Frameworks/OpenGL.framework/Headers -isystem /usr/local/opt/qt5/lib/QtCore.framework/Headers -isystem /usr/local/opt/qt5/./mkspecs/macx-clang -std=c++1z -fPIC -std=gnu++11 -o CMakeFiles/foo.dir/main.cpp.o -c /Users/nega/foo/main.cpp
[100%] Linking CXX executable foo
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_link_script CMakeFiles/foo.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++1z -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/foo.dir/main.cpp.o -o foo -L/usr/local/opt/boost#1.55/lib -Wl,-rpath,/usr/local/opt/boost#1.55/lib /usr/local/opt/boost#1.55/lib/libboost_serialization-mt.dylib /usr/local/opt/boost#1.55/lib/libboost_system-mt.dylib /usr/local/opt/qt5/lib/QtWidgets.framework/QtWidgets /usr/local/opt/qt5/lib/QtGui.framework/QtGui /usr/local/opt/qt5/lib/QtCore.framework/QtCore
[100%] Built target foo
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_progress_start /Users/nega/foo/CMakeFiles 0
If you comment out the Qt5 usage in our CMakeLists.txt and configure and build again, you'll see the -std=gnu++11 disappear (along with the -fPIC which Qt is also adding).
CMakeLists.txt:
cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
set(BOOST_ROOT "/usr/local/opt/boost#1.55")
execute_process(COMMAND brew --prefix qt5
COMMAND tr -d \\n
OUTPUT_VARIABLE QT5_BREW_PATH)
find_package(Boost COMPONENTS serialization system)
#find_package(Qt5 COMPONENTS Widgets HINTS ${QT5_BREW_PATH})
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo main.cpp)
target_link_libraries(foo
PRIVATE ${Boost_LIBRARIES}
# PRIVATE Qt5::Widgets
)
make output (abridged):
[...]
[ 50%] Building CXX object CMakeFiles/foo.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -I/usr/local/opt/boost#1.55/include -std=c++1z -o CMakeFiles/foo.dir/main.cpp.o -c /Users/nega/foo/main.cpp
[100%] Linking CXX executable foo
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_link_script CMakeFiles/foo.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++1z -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/foo.dir/main.cpp.o -o foo -L/usr/local/opt/boost#1.55/lib -Wl,-rpath,/usr/local/opt/boost#1.55/lib /usr/local/opt/boost#1.55/lib/libboost_serialization-mt.dylib /usr/local/opt/boost#1.55/lib/libboost_system-mt.dylib
[100%] Built target foo
[...]
Unfortunately, after some brief digging I couldn't see where Qt was setting -std=gnu++11 in its *Config.cmake files. It must be reaching into CMake more than just a few grep's could find. Maybe reading through cmake --trace will provide some insight.
Curiously though, what ever it's doing respects CXX_STANDARD. If we tweak our original CMakeLists.txt and configure and build again:
CMakeLists.txt (abridged):
cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
set(BOOST_ROOT "/usr/local/opt/boost#1.55")
execute_process(COMMAND brew --prefix qt5
[...]
make output (abridged):
[...]
[ 50%] Building CXX object CMakeFiles/foo.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I/usr/local/opt/boost#1.55/include -iframework /usr/local/opt/qt5/lib -isystem /usr/local/opt/qt5/lib/QtWidgets.framework/Headers -isystem /usr/local/opt/qt5/lib/QtGui.framework/Headers -isystem /System/Library/Frameworks/OpenGL.framework/Headers -isystem /usr/local/opt/qt5/lib/QtCore.framework/Headers -isystem /usr/local/opt/qt5/./mkspecs/macx-clang -std=c++1z -fPIC -std=gnu++14 -o CMakeFiles/foo.dir/main.cpp.o -c /Users/nega/foo/main.cpp
[100%] Linking CXX executable foo
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_link_script CMakeFiles/foo.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++1z -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/foo.dir/main.cpp.o -o foo -L/usr/local/opt/boost#1.55/lib -Wl,-rpath,/usr/local/opt/boost#1.55/lib /usr/local/opt/boost#1.55/lib/libboost_serialization-mt.dylib /usr/local/opt/boost#1.55/lib/libboost_system-mt.dylib /usr/local/opt/qt5/lib/QtWidgets.framework/QtWidgets /usr/local/opt/qt5/lib/QtGui.framework/QtGui /usr/local/opt/qt5/lib/QtCore.framework/QtCore
[100%] Built target foo
[...]
You can see that the (Qt added) -fPIC -std=gnu++11 is now -fPIC -std=gnu++14. Unfortunately this won't help you until CMake 3.8.0 is released and its CXX_STANDARD/CMAKE_CXX_STANDARD will understand "C++17".

Output of 'make' is a shared object and not an executable

Edit: It appears to be a g++ issue, as compiling with clang++ does output an executable file.
I've written a C++ application that has a main function, creates an application window, loads a 3D fbx file and draws that using opengl. To create the Makefile for compiling i'm using a CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
project(solight)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
INCLUDE_DIRECTORIES(lib/include)
###########################################
#SET THIS TO X32 IN CASE OF A 32 BIT SYSTEM
###########################################
set (ARCH x64)
set (SRC_LIST
src/assetmanager.cpp src/assetmanager.h
src/mesh.cpp src/mesh.h
src/model.cpp src/model.h
src/modelloader.h
src/main.cpp
src/math.h
src/fbxmodelloader.cpp src/fbxmodelloader.h
src/rendermodule.h
src/openglrendermodule.cpp src/openglrendermodule.h
src/textureloader.h
src/engine.cpp src/enginemodules.cpp src/engine.h
)
##########################
#EXTERNAL LIBRARY HANDLING
##########################
set (LINUX_DEPS
libfbxsdk.a
pthread
libSDL2.a
GL
libGLEW.a
dl
)
set (WIN32_DEPS
)
set (APPLE_DEPS
)
if (UNIX AND NOT APPLE)
set (DEPS ${LINUX_DEPS})
set (OS Linux)
endif()
if (APPLE)
set (DEPS ${APPLE_DEPS})
set (OS Apple)
endif()
if (WIN32)
set (DEPS ${WIN32_DEPS})
set (OS WIN32)
endif()
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/${OS}/${ARCH})
####################
#EXECUTBALE CREATION
####################
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${DEPS})
So after running the makefile that cmake created, the output is not an executable as expected, but a shared object file. If i run the file command on it this is the output:
solight: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=f20c07c8743a70bca20d4a0d9f50fcb108b8140e, not stripped
When executing
/lib64/ld-linux-x86-64.so.2 ./solight --verify
the program executes as it should.
But when i execute the file through the terminal it runs just fine, creates the window and renders the model.
Any explantion as to why this is a shared object file?
Thanks in advance.
Edit:
When running
make VERBOSE=1
the output is:
/usr/bin/cmake -H/home/wouter/Documents/Solight -B/home/wouter/Documents/Solight/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/wouter/Documents/Solight/build/CMakeFiles /home/wouter/Documents/Solight/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/wouter/Documents/Solight/build'
make -f CMakeFiles/solight.dir/build.make CMakeFiles/solight.dir/depend
make[2]: Entering directory '/home/wouter/Documents/Solight/build'
cd /home/wouter/Documents/Solight/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/wouter/Documents/Solight /home/wouter/Documents/Solight /home/wouter/Documents/Solight/build /home/wouter/Documents/Solight/build /home/wouter/Documents/Solight/build/CMakeFiles/solight.dir/DependInfo.cmake --color=
Dependee "/home/wouter/Documents/Solight/build/CMakeFiles/solight.dir/DependInfo.cmake" is newer than depender "/home/wouter/Documents/Solight/build/CMakeFiles/solight.dir/depend.internal".
Dependee "/home/wouter/Documents/Solight/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/wouter/Documents/Solight/build/CMakeFiles/solight.dir/depend.internal".
Scanning dependencies of target solight
make[2]: Leaving directory '/home/wouter/Documents/Solight/build'
make -f CMakeFiles/solight.dir/build.make CMakeFiles/solight.dir/build
make[2]: Entering directory '/home/wouter/Documents/Solight/build'
[ 11%] Building CXX object CMakeFiles/solight.dir/src/assetmanager.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/assetmanager.cpp.o -c /home/wouter/Documents/Solight/src/assetmanager.cpp
[ 22%] Building CXX object CMakeFiles/solight.dir/src/mesh.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/mesh.cpp.o -c /home/wouter/Documents/Solight/src/mesh.cpp
[ 33%] Building CXX object CMakeFiles/solight.dir/src/model.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/model.cpp.o -c /home/wouter/Documents/Solight/src/model.cpp
[ 44%] Building CXX object CMakeFiles/solight.dir/src/main.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/main.cpp.o -c /home/wouter/Documents/Solight/src/main.cpp
[ 55%] Building CXX object CMakeFiles/solight.dir/src/fbxmodelloader.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/fbxmodelloader.cpp.o -c /home/wouter/Documents/Solight/src/fbxmodelloader.cpp
[ 66%] Building CXX object CMakeFiles/solight.dir/src/openglrendermodule.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/openglrendermodule.cpp.o -c /home/wouter/Documents/Solight/src/openglrendermodule.cpp
[ 77%] Building CXX object CMakeFiles/solight.dir/src/engine.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/engine.cpp.o -c /home/wouter/Documents/Solight/src/engine.cpp
[ 88%] Building CXX object CMakeFiles/solight.dir/src/enginemodules.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/enginemodules.cpp.o -c /home/wouter/Documents/Solight/src/enginemodules.cpp
[100%] Linking CXX executable solight
/usr/bin/cmake -E cmake_link_script CMakeFiles/solight.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++14 CMakeFiles/solight.dir/src/assetmanager.cpp.o CMakeFiles/solight.dir/src/mesh.cpp.o CMakeFiles/solight.dir/src/model.cpp.o CMakeFiles/solight.dir/src/main.cpp.o CMakeFiles/solight.dir/src/fbxmodelloader.cpp.o CMakeFiles/solight.dir/src/openglrendermodule.cpp.o CMakeFiles/solight.dir/src/engine.cpp.o CMakeFiles/solight.dir/src/enginemodules.cpp.o -o solight -L/home/wouter/Documents/Solight/lib/Linux/x64 -rdynamic -Wl,-Bstatic -lfbxsdk -Wl,-Bdynamic -lpthread -Wl,-Bstatic -lSDL2 -Wl,-Bdynamic -lGL -Wl,-Bstatic -lGLEW -Wl,-Bdynamic -ldl -Wl,-rpath,/home/wouter/Documents/Solight/lib/Linux/x64
/home/wouter/Documents/Solight/lib/Linux/x64/libfbxsdk.a(fbxutils.o): In function `fbxsdk_2015_1::FbxPathUtils::GenerateFileName(char const*, char const*)':
(.text+0x4c8): warning: the use of `tempnam' is dangerous, better use `mkstemp'
make[2]: Leaving directory '/home/wouter/Documents/Solight/build'
[100%] Built target solight
make[1]: Leaving directory '/home/wouter/Documents/Solight/build'
/usr/bin/cmake -E cmake_progress_start /home/wouter/Documents/Solight/build/CMakeFiles 0
This may happen when application is compiled with special CFLAGS e.g. -pie -fPIE:
$ echo 'int main() { return 0; }' | gcc -x c - -fPIE -pie
$ file a.out
a.out: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24,
Perhaps you could run your make with VERBOSE=1 and see if that's the case? In general file may use heuristics to identify filetype so you shouldn't rely on it too heavily.
As for your error with ld.so, you are using the wrong, 32-bit, dynamic linker to run 64-bit app. Use /lib64/ld-linux-x86-64.so.2 instead (as file told you).
EDIT: Another option is that your GCC is built with --enable-default-pie which seems to be the case for modern Ubuntu. You can disable this feature by cmaking with CFLAGS=-no-pie (or -nopie, depending on GCC version) but I'd rather not do that - PIE'ed executables make your system safer by allowing ASLR to do better job.
I found the root cause is the -shared flag in CMAKE_EXE_LINKER_FLAGS.
when I delete -shared, everything is ok.

Unable to load shared object: undefined symbol

I'm trying to create simple lib for the R with statically linked boost.
CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(TheRPath)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror")
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.50.0 REQUIRED COMPONENTS filesystem)
include_directories(${Boost_INCLUDE_DIRS})
include_directories("/usr/share/R/include")
set(SOURCE_FILES Path.cpp Path.h)
add_library(therpath SHARED ${SOURCE_FILES})
target_link_libraries(therpath ${Boost_LIBRARIES})
Interpreter gives me an error when I'm trying to load shared object.
> dyn.load("libtherpath.so")
Error in dyn.load("libtherpath.so") :
unable to load shared object 'libtherpath.so':
libtherpath.so: undefined symbol: _ZN5boost6system15system_categoryEv
I have the following code:
Path.h
#ifndef PATH_H
#define PATH_H
#include <Rinternals.h>
extern "C" SEXP foo(SEXP snapshotPath);
#endif // PATH_H
Path.cpp
#include <string>
#include <boost/filesystem.hpp>
#include "Path.h"
extern "C" SEXP foo(SEXP snapshotPath) {
std::string path(R_CHAR(STRING_ELT(snapshotPath, 0)));
std::cerr << path << boost::filesystem::path::preferred_separator << "file.txt" << std::endl;
return R_NilValue;
}
Could you tell me what I'm doing wrong?
UPD 1
Output of make VERBOSE=1:
/home/user/Soft/clion-latest/bin/cmake/bin/cmake -H/home/user/Workspace/TheRPath -B/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug --check-build-system CMakeFiles/Makefile.cmake 0
/home/user/Soft/clion-latest/bin/cmake/bin/cmake -E cmake_progress_start /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug/CMakeFiles /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
make -f CMakeFiles/therpath.dir/build.make CMakeFiles/therpath.dir/depend
make[2]: Entering directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
cd /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug && /home/user/Soft/clion-latest/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /home/user/Workspace/TheRPath /home/user/Workspace/TheRPath /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug/CMakeFiles/therpath.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
make -f CMakeFiles/therpath.dir/build.make CMakeFiles/therpath.dir/build
make[2]: Entering directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
[ 50%] Building CXX object CMakeFiles/therpath.dir/Path.cpp.o
/usr/bin/c++ -Dtherpath_EXPORTS -std=c++11 -Wall -Werror -g -fPIC -I/usr/share/R/include -o CMakeFiles/therpath.dir/Path.cpp.o -c /home/user/Workspace/TheRPath/Path.cpp
[100%] Linking CXX shared library libtherpath.so
/home/user/Soft/clion-latest/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/therpath.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -std=c++11 -Wall -Werror -g -shared -Wl,-soname,libtherpath.so -o libtherpath.so CMakeFiles/therpath.dir/Path.cpp.o /usr/lib/x86_64-linux-gnu/libboost_filesystem.a
make[2]: Leaving directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
[100%] Built target therpath
make[1]: Leaving directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
/home/user/Soft/clion-latest/bin/cmake/bin/cmake -E cmake_progress_start /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug/CMakeFiles 0
UPD 2
/home/user/Soft/clion-latest/bin/cmake/bin/cmake -H/home/user/Workspace/TheRPath -B/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug --check-build-system CMakeFiles/Makefile.cmake 0
/home/user/Soft/clion-latest/bin/cmake/bin/cmake -E cmake_progress_start /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug/CMakeFiles /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
make -f CMakeFiles/therpath.dir/build.make CMakeFiles/therpath.dir/depend
make[2]: Entering directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
cd /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug && /home/user/Soft/clion-latest/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /home/user/Workspace/TheRPath /home/user/Workspace/TheRPath /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug /home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug/CMakeFiles/therpath.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
make -f CMakeFiles/therpath.dir/build.make CMakeFiles/therpath.dir/build
make[2]: Entering directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
[ 50%] Building CXX object CMakeFiles/therpath.dir/Path.cpp.o
/usr/bin/c++ -Dtherpath_EXPORTS -std=c++11 -Wall -Werror -g -fPIC -I/usr/share/R/include -o CMakeFiles/therpath.dir/Path.cpp.o -c /home/user/Workspace/TheRPath/Path.cpp
[100%] Linking CXX shared library libtherpath.so
/home/user/Soft/clion-latest/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/therpath.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -std=c++11 -Wall -Werror -g -shared -Wl,-soname,libtherpath.so -o libtherpath.so CMakeFiles/therpath.dir/Path.cpp.o /usr/lib/x86_64-linux-gnu/libboost_system.a /usr/lib/x86_64-linux-gnu/libboost_filesystem.a
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libboost_system.a(error_code.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/lib/x86_64-linux-gnu/libboost_system.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [libtherpath.so] Error 1
make[2]: Leaving directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
make[1]: *** [CMakeFiles/therpath.dir/all] Error 2
make[1]: Leaving directory `/home/user/.CLion12/system/cmake/generated/a69e8583/a69e8583/Debug'
make: *** [all] Error 2
libboost_filesystem depends on libboost_system. You need to add it to your CMakeLists.txt:
find_package(Boost REQUIRED COMPONENTS filesystem system)
Note I omitted the optional Boost version number, because you probably don't really need or want to specify it. But you can if you feel compelled.