Why include paths are inherited even for private linking - c++

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.

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

CMake C++ compile command

I'm currently learning CMake, which I understand to be a build file generator, and I wanted to see the exact command that CMake was running to compile and link my C++ files. For example, if I'm working with a single file main.cpp and I were to compile it with gcc, I would run gcc -o main main.cpp. How would I see the C++ command that CMake is running? I tried make VERBOSE=1 but that only reveals CMake-related commands instead of C++ compiler commands.
// main.cpp
#include <iostream>
int main()
{
std::cout << "Hello world" << std::endl;
}
//CMakeLists.txt
cmake_minimum_required(VERSION 3.2)
project(example LANGUAGES CXX)
add_executable(main main.cpp)
This creates a Makefile with the following contents:
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.14
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/local/Cellar/cmake/3.14.5/bin/cmake
# The command to remove a file.
RM = /usr/local/Cellar/cmake/3.14.5/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /Users/.../Desktop/cpp
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /Users/.../Desktop/cpp/build
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target rebuild_cache
rebuild_cache:
#$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/local/Cellar/cmake/3.14.5/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# Special rule for the target edit_cache
edit_cache:
#$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/local/Cellar/cmake/3.14.5/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /Users/.../Desktop/cpp/build/CMakeFiles /Users/.../Desktop/cpp/build/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /Users/.../Desktop/cpp/build/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast
# clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
#=============================================================================
# Target rules for targets named main
# Build rule for target.
main: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 main
.PHONY : main
# fast build rule for target.
main/fast:
$(MAKE) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
.PHONY : main/fast
main.o: main.cpp.o
.PHONY : main.o
# target to build an object file
main.cpp.o:
$(MAKE) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/main.cpp.o
.PHONY : main.cpp.o
main.i: main.cpp.i
.PHONY : main.i
# target to preprocess a source file
main.cpp.i:
$(MAKE) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/main.cpp.i
.PHONY : main.cpp.i
main.s: main.cpp.s
.PHONY : main.s
# target to generate assembly for a file
main.cpp.s:
$(MAKE) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/main.cpp.s
.PHONY : main.cpp.s
# Help Target
help:
#echo "The following are some of the valid targets for this Makefile:"
#echo "... all (the default if no target is provided)"
#echo "... clean"
#echo "... depend"
#echo "... rebuild_cache"
#echo "... edit_cache"
#echo "... main"
#echo "... main.o"
#echo "... main.i"
#echo "... main.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system
make VERBOSE=1 returns:
/usr/local/Cellar/cmake/3.14.5/bin/cmake -S/Users/.../Desktop/cpp -B/Users/.../Desktop/cpp/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_progress_start /Users/.../Desktop/cpp/build/CMakeFiles /Users/.../Desktop/cpp/build/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/main.dir/build.make CMakeFiles/main.dir/depend
cd /Users/.../Desktop/cpp/build && /usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_depends "Unix Makefiles" /Users/.../Desktop/cpp /Users/.../Desktop/cpp /Users/.../Desktop/cpp/build /Users/.../Desktop/cpp/build /Users/.../Desktop/cpp/build/CMakeFiles/main.dir/DependInfo.cmake --color=
Dependee "/Users/.../Desktop/cpp/build/CMakeFiles/main.dir/DependInfo.cmake" is newer than depender "/Users/.../Desktop/cpp/build/CMakeFiles/main.dir/depend.internal".
Dependee "/Users/.../Desktop/cpp/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/.../Desktop/cpp/build/CMakeFiles/main.dir/depend.internal".
Scanning dependencies of target main
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -o CMakeFiles/main.dir/main.cpp.o -c /Users/.../Desktop/cpp/main.cpp
[100%] Linking CXX executable main
/usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/main.dir/main.cpp.o -o main
[100%] Built target main
/usr/local/Cellar/cmake/3.14.5/bin/cmake -E cmake_progress_start /Users/.../Desktop/cpp/build/CMakeFiles 0

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

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? :-)

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.