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

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.

Related

error linking stdlib.h when building OpenCV on a Chromebook

Configuration seems to run successfully...
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
-- The CXX compiler identification is GNU 7.3.0
-- The C compiler identification is GNU 7.3.0
-- Check for working CXX compiler: /usr/local/bin/c++
-- Check for working CXX compiler: /usr/local/bin/c++ -- works
(etc)
then when I run make install,
chronos#localhost ~/Downloads/python/opencv-3.4.3/build $ sudo make install
Scanning dependencies of target gen-pkgconfig
[ 0%] Generate opencv.pc
[ 0%] Built target gen-pkgconfig
Scanning dependencies of target libjpeg-turbo
[ 0%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcapimin.c.o
[ 0%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcapistd.c.o`
(etc)
`[ 5%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_print.c.o
[ 5%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_read.c.o
[ 5%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_strip.c.o
[ 5%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_swab.c.o
[ 5%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_thunder.c.o
[ 5%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_tile.c.o
[ 5%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_version.c.o
[ 5%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_warning.c.o
[ 5%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_write.c.o
[ 5%] Building C object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_zip.c.o
[ 5%] Building CXX object 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_stream.cxx.o
In file included from /usr/local/include/c++/7.3.0/ext/string_conversions.h:41:0,
from /usr/local/include/c++/7.3.0/bits/basic_string.h:6349,
from /usr/local/include/c++/7.3.0/string:52,
from /usr/local/include/c++/7.3.0/bits/locale_classes.h:40,
from /usr/local/include/c++/7.3.0/bits/ios_base.h:41,
from /usr/local/include/c++/7.3.0/ios:42,
from /usr/local/include/c++/7.3.0/ostream:38,
from /usr/local/include/c++/7.3.0/iostream:39,
from /home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/libtiff/tiffio.hxx:34,
from /home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/libtiff/tif_stream.cxx:31:
/usr/local/include/c++/7.3.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
make[2]: *** [3rdparty/libtiff/CMakeFiles/libtiff.dir/build.make:557: 3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_stream.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:387: 3rdparty/libtiff/CMakeFiles/libtiff.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
I have tried disabling 3rd party libraries and it fails later on, with the same error for a different component.
chronos#localhost ~/Downloads/python/opencv-3.4.3/build $ sudo make install
[ 0%] Generate opencv.pc
[ 0%] Built target gen-pkgconfig
[ 9%] Built target libwebp
[ 11%] Built target libjasper
[ 13%] Built target libpng
[ 13%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/Half/half.cpp.o
In file included from /usr/local/include/c++/7.3.0/ext/string_conversions.h:41:0,
from /usr/local/include/c++/7.3.0/bits/basic_string.h:6349,
from /usr/local/include/c++/7.3.0/string:52,
from /usr/local/include/c++/7.3.0/bits/locale_classes.h:40,
from /usr/local/include/c++/7.3.0/bits/ios_base.h:41,
from /usr/local/include/c++/7.3.0/ios:42,
from /usr/local/include/c++/7.3.0/ostream:38,
from /usr/local/include/c++/7.3.0/iostream:39,
from /home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/openexr/Half/half.h:88,
from /home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/openexr/Half/half.cpp:48:
/usr/local/include/c++/7.3.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
Versions and library appear fine...
chronos#localhost ~/Downloads/python/opencv-3.4.3/build $ gcc --version
gcc (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
chronos#localhost ~/Downloads/python/opencv-3.4.3/build $ sudo find / -type f -name "*stdlib.h"
/usr/local/include/stdlib.h
/usr/local/include/bits/stdlib.h
/usr/local/include/c++/7.3.0/stdlib.h
/usr/local/include/c++/7.3.0/tr1/stdlib.h
/mnt/stateful_partition/dev_image/include/stdlib.h
/mnt/stateful_partition/dev_image/include/bits/stdlib.h
/mnt/stateful_partition/dev_image/include/c++/7.3.0/stdlib.h
/mnt/stateful_partition/dev_image/include/c++/7.3.0/tr1/stdlib.h
with VERBOSE=1,
make -f 3rdparty/openexr/CMakeFiles/IlmImf.dir/build.make 3rdparty/openexr/CMakeFiles/IlmImf.dir/build
make[2]: Entering directory '/home/chronos/user/Downloads/python/opencv-3.4.3/build'
[ 12%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/Half/half.cpp.o
cd /home/chronos/user/Downloads/python/opencv-3.4.3/build/3rdparty/openexr && /usr/local/bin/c++ -I/home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/openexr/IlmImf -I/home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/openexr/Imath -I/home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/openexr/IlmThread -I/home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/openexr/Iex -I/home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/openexr/Half -I/home/chronos/user/Downloads/python/opencv-3.4.3/build/3rdparty/openexr -I/home/chronos/user/Downloads/python/opencv-3.4.3/build -isystem /usr/local/include -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Winit-self -Wpointer-arith -Wsign-promo -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -Wno-shadow -Wno-unused -Wno-sign-compare -Wno-undef -Wno-missing-declarations -Wno-uninitialized -Wno-switch -Wno-parentheses -Wno-array-bounds -Wno-extra -Wno-deprecated-declarations -Wno-misleading-indentation -Wno-deprecated -Wno-suggest-override -Wno-implicit-fallthrough -O3 -DNDEBUG -DNDEBUG -fPIC -o CMakeFiles/IlmImf.dir/Half/half.cpp.o -c /home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/openexr/Half/half.cpp
In file included from /usr/local/include/c++/7.3.0/ext/string_conversions.h:41:0,
from /usr/local/include/c++/7.3.0/bits/basic_string.h:6349,
from /usr/local/include/c++/7.3.0/string:52,
from /usr/local/include/c++/7.3.0/bits/locale_classes.h:40,
from /usr/local/include/c++/7.3.0/bits/ios_base.h:41,
from /usr/local/include/c++/7.3.0/ios:42,
from /usr/local/include/c++/7.3.0/ostream:38,
from /usr/local/include/c++/7.3.0/iostream:39,
from /home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/openexr/Half/half.h:88,
from /home/chronos/user/Downloads/python/opencv-3.4.3/3rdparty/openexr/Half/half.cpp:48:
/usr/local/include/c++/7.3.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
make[2]: *** [3rdparty/openexr/CMakeFiles/IlmImf.dir/build.make:63: 3rdparty/openexr/CMakeFiles/IlmImf.dir/Half/half.cpp.o] Error 1
make[2]: Leaving directory '/home/chronos/user/Downloads/python/opencv-3.4.3/build'
make[1]: *** [CMakeFiles/Makefile2:442: 3rdparty/openexr/CMakeFiles/IlmImf.dir/all] Error 2
make[1]: Leaving directory '/home/chronos/user/Downloads/python/opencv-3.4.3/build'
make: *** [Makefile:163: all] Error 2

Problems linking Bonmin using Cmake under macOS High Sierra with "ld: framework not found -lAccelerate"

I am currently trying to link Bonmin using cmake in my project under macOS High Sierra (10.13.4) with Xcode version 9.3. Before I describe the setup I should mention that the Bonmin example (/PATH_TO_BONMIN/Bonmin/examples/CppExample) compiles with the included make files. Later example I try to get to work in my environment, but it is not working. Thus, I think there must be an incompatibility.
Bonmin 1.8 (https://www.coin-or.org/Tarballs/Bonmin/) was build on my Mac using
../configure -C --disable-shared F77="/usr/local/bin/gfortran" FFLAGS="-fexceptions -m64 -fbackslash" CFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch x86_64 -m64" CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch x86_64 -m64"
My FindBonmin.cmake uses the package configuration files from "${BONMIN_LIBRARY_DIR}/pkgconfig":
find_path(BONMIN_LIBRARY_DIR
NAMES libbonmin.a
HINTS ...
HINTS /usr/local/include/coin
HINTS ${BONMIN_ROOT_DIR}/include/coin
HINTS ${BONMIN_ROOT_DIR}/include
)
if(IS_DIRECTORY "${BONMIN_LIBRARY_DIR}/pkgconfig")
set(CMAKE_PREFIX_PATH "${BONMIN_LIBRARY_DIR}/pkgconfig")
set(ENV{PKG_CONFIG_PATH} "${BONMIN_LIBRARY_DIR}/pkgconfig")
else()
message("Directory ${BONMIN_LIBRARY_DIR}/pkgconfig does not exist!")
endif()
From this I get the following:
${BONMIN_LIBRARY_DIR}/pkgconfig =
/Users/<PATH>/Bonmin-1.8/build/lib/pkgconfig
${PKG_BONMIN_INCLUDE_DIRS} =
/Users/<PATH>/Bonmin-1.8/build/include/coin;/Users/<PATH>/Bonmin-1.8/build/include/coin/ThirdParty;/Users/<PATH>/Bonmin-1.8/build/include/coin;/Users/<PATH>/Bonmin-1.8/build/include/coin/ThirdParty
${PKG_BONMIN_LDFLAGS} = -L/Users/<PATH>/Bonmin-1.8/build/lib;-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64;-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/../../../x86_64;-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3;-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/../../..;-lbonmin;-lCbcSolver;-lCbc;-lCgl;-lOsiClp;-lClpSolver;-lClp;-lcoinasl;-lm;-ldl;-lOsi;-lCoinUtils;-lbz2;-lz;-framework;Accelerate;-lm;-lipopt;-framework;Accelerate;-lm;-ldl;-lcoinmumps;-framework;Accelerate;-lgfortranbegin;-lgfortran;-lSystem
This is used for the example:
include_directories(${PKG_BONMIN_INCLUDE_DIRS} )
add_executable(bonminExample runnables/bonminExample.cpp)
target_link_libraries(bonminExample ${PKG_BONMIN_LDFLAGS})
Additional information:
cmake_minimum_required(VERSION 3.6)
project(MyProject CXX)
# The version number.
set (MyProject_VERSION_MAJOR 1)
set (MyProject_VERSION_MINOR 0)
set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/5.0.1/bin/clang" CACHE FILEPATH "Path to the used C compiler; default clang." FORCE)
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/5.0.1/bin/clang++" CACHE FILEPATH "Path to the used C++ compiler; default clang++." FORCE)
set(OPENMP_LIBRARIES "/usr/local/Cellar/llvm/5.0.1/lib" CACHE FILEPATH "Path to the OpenMP libraries." FORCE)
set(OPENMP_INCLUDES "/usr/local/Cellar/llvm/5.0.1/include" CACHE FILEPATH "Path to the OpenMP includes." FORCE)
## Set c++14
set(CMAKE_CXX_STANDARD 14)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
...
The error message I get, while trying to link Bonmin is:
ld: framework not found -lAccelerate
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/Users/<PATH>/myproject/bin/bonminExample] Error 1
make[1]: *** [src/CMakeFiles/bonminExample.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
With the details:
[ 3%] Linking CXX executable /Users/<PATH>/myproject/bin/bonminExample
cd /Users/<PATH>/build_debug/src && /opt/local/bin/cmake -E cmake_link_script CMakeFiles/bonminExample.dir/link.txt --verbose=1
cd /Users/<PATH>/build_debug && /opt/local/bin/cmake -E cmake_depends "Unix Makefiles" /Users/<PATH>/myproject /Users/<PATH>/build_debug/googletest-src/googlemock /Users/<PATH>/build_debug /Users/<PATH>/build_debug/googletest-build/googlemock /Users/<PATH>/build_debug/googletest-build/googlemock/CMakeFiles/gmock_autogen.dir/DependInfo.cmake --color=
cd /Users/<PATH>/build_debug && /opt/local/bin/cmake -E cmake_depends "Unix Makefiles" /Users/<PATH>/myproject/ /Users/<PATH>/myproject/src /Users/<PATH>/build_debug /Users/<PATH>/build_debug/src /Users/<PATH>/build_debug/src/CMakeFiles/PGT.dir/DependInfo.cmake --color=
/usr/local/Cellar/llvm/5.0.1/bin/clang++ -fopenmp=libomp -Wno-unused-command-line-argument -DCOIN_USE_MUMPS_MPI_H -fno-common -no-cpp-precomp -fexceptions -arch x86_64 -m64 -DBONMIN_BUILD -march=native -g -Wall -ggdb -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/bonminExample.dir/runnables/BonminExample.cpp.o CMakeFiles/bonminExample.dir/bonminExample_autogen/mocs_compilation.cpp.o -o /Users/<PATH>/myproject/bin/bonminExample -L/usr/local/Cellar/llvm/5.0.1/lib -L/Users/<PATH>/external_libraries/ogdf20170723 -Wl,-rpath,/usr/local/Cellar/llvm/5.0.1/lib -Wl,-rpath,/Users/<PATH>/external_libraries/ogdf20170723 -L/Users/<PATH>/external_libraries/Bonming-1.8/build/lib -L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64 -L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/../../../x86_64 -L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3 -L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/../../.. -lbonmin -lCbcSolver -lCbc -lCgl -lOsiClp -lClpSolver -lClp -lcoinasl -lm -ldl -lOsi -lCoinUtils -lbz2 -lz -framework -lAccelerate -lm -lipopt -framework -lAccelerate -lm -ldl -lcoinmumps -framework -lAccelerate -lgfortranbegin -lgfortran -lSystem -lm -ldl -lOsi -lCoinUtils -lbz2 -lz -lipopt -lcoinmumps -lgfortranbegin -lgfortran -lSystem
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f googletest-build/googlemock/CMakeFiles/gmock_autogen.dir/build.make googletest-build/googlemock/CMakeFiles/gmock_autogen.dir/build
[ 4%] Automatic MOC for target gmock
cd /Users/<PATH>/build_debug/googletest-build/googlemock && /opt/local/bin/cmake -E cmake_autogen /Users/<PATH>/build_debug/googletest-build/googlemock/CMakeFiles/gmock_autogen.dir Debug
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f src/CMakeFiles/PGT.dir/build.make src/CMakeFiles/PGT.dir/build
ld: framework not found -lAccelerate
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/Users/<PATH>/myproject/bin/bonminExample] Error 1
make[1]: *** [src/CMakeFiles/bonminExample.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f src/CMakeFiles/PGTIP.dir/build.make src/CMakeFiles/PGTIP.dir/build
Does anybody know what might be an issue or even has a solution to it?
Note that the make file from the Bonmin example gives me the following:
MBP:CppExample myname$ make VERBOSE=1
clang++ -fno-common -no-cpp-precomp -fexceptions -arch x86_64 -m64 -DBONMIN_BUILD `PKG_CONFIG_PATH=/Users/<PATH>/Bonmin-1.8/build/lib64/pkgconfig:/Users/<PATH>/Bonmin-1.8/build/lib/pkgconfig:/Users/<PATH>/Bonmin-1.8/build/share/pkgconfig:/opt/X11/lib/pkgconfig pkg-config --cflags bonmin` -c -o MyBonmin.o `test -f '../../../../Bonmin/examples/CppExample/MyBonmin.cpp' || echo '../../../../Bonmin/examples/CppExample/'`../../../../Bonmin/examples/CppExample/MyBonmin.cpp
clang++ -fno-common -no-cpp-precomp -fexceptions -arch x86_64 -m64 -DBONMIN_BUILD `PKG_CONFIG_PATH=/Users/<PATH>/Bonmin-1.8/build/lib64/pkgconfig:/Users/<PATH>/Bonmin-1.8/build/lib/pkgconfig:/Users/<PATH>/Bonmin-1.8/build/share/pkgconfig:/opt/X11/lib/pkgconfig pkg-config --cflags bonmin` -c -o MyTMINLP.o `test -f '../../../../Bonmin/examples/CppExample/MyTMINLP.cpp' || echo '../../../../Bonmin/examples/CppExample/'`../../../../Bonmin/examples/CppExample/MyTMINLP.cpp
bla=;\
for file in MyBonmin.o MyTMINLP.o; do bla="$bla `echo $file`"; done; \
clang++ -fno-common -no-cpp-precomp -fexceptions -arch x86_64 -m64 -DBONMIN_BUILD -o CppExample $bla `PKG_CONFIG_PATH=/Users/<PATH>/Bonmin-1.8/build/lib64/pkgconfig:/Users/<PATH>/Bonmin-1.8/build/lib/pkgconfig:/Users/<PATH>/Bonmin-1.8/build/share/pkgconfig:/opt/X11/lib/pkgconfig pkg-config --libs bonmin`
Before XXX_LDFLAGS variable, obtained from PkgConfig module, is used in target_link_libraries call, modify that variable:
string(REPLACE "-framework;" "-framework " PKG_BONMIN_LDFLAGS "${PKG_BONMIN_LDFLAGS}")
(The quotation marks at "${PKG_BONMIN_LDFLAGS}" are important.)
After that, -framework option will be processed correctly:
target_link_libraries(... ${PKG_BONMIN_LDFLAGS})
Explanations
It seems that CMake incorrectly works with pkg-config when framework is used. When extract
-framework Acceletate
from the pkg-config output, these 2 words are interpreted as separate arguments. So, when passed to target_link_libraries:
target_link_libraries(... -framework Acceletate)
-l is appended to the second word according to the command's rules:
ld .... -framework -lAccelerate
Proper command's call should be
target_link_libraries(... "-framework Acceletate")
And this is exactly the purpose of above-mentioned string(REPLACE): It replaces CMake arguments delimiter ;, following -framework option, with normal space .

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

Linker error when using cinder and poco

I'm trying to use libcinder to make some visualizations. In integrating in my existing codebase, I've run into some linker errors that I can't figure out.
I've boiled the problem down to a minimal example, with the following results:
cd /build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/BasicApp.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/BasicApp.dir/BasicApp.cpp.o -o ../bin/BasicApp -rdynamic -lPocoUtil -lPocoFoundation
make[2]: Leaving directory '/build'
[100%] Built target BasicApp
make[1]: Leaving directory '/build'
/usr/bin/cmake -E cmake_progress_start /build/CMakeFiles 0
If don't involve cinder at all, everything works fine, as seen above. if I add my function to the minimal cinder example (BasicApp), I get the following output on compilation:
cd /build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/BasicApp.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/BasicApp.dir/BasicApp.cpp.o -o ../bin/BasicApp -rdynamic -lPocoUtil -lPocoFoundation /cinder/lib/linux/x86_64/ogl/Release/libcinder.a -lGLU -lGL -lSM -lICE -lX11 -lXext -lXcursor -lXinerama -lXrandr -lXi -lz -lcurl -lfontconfig -lpulse -lmpg123 -lsndfile -lgobject-2.0 -lglib-2.0 -lgstreamer-1.0 -lgstbase-1.0 -lgstapp-1.0 -lgstvideo-1.0 -lgstgl-1.0 /cinder/lib/linux/x86_64//libboost_system.a /cinder/lib/linux/x86_64//libboost_filesystem.a -ldl -lpthread
CMakeFiles/BasicApp.dir/BasicApp.cpp.o: In function `load_images(std::string, std::string, int, int)':
BasicApp.cpp:(.text+0xca2): undefined reference to `Poco::DirectoryIterator::DirectoryIterator(std::string const&)'
BasicApp.cpp:(.text+0xd57): undefined reference to `Poco::DirectoryIterator::DirectoryIterator(std::string const&)'
collect2: error: ld returned 1 exit status
src/CMakeFiles/BasicApp.dir/build.make:118: recipe for target 'bin/BasicApp' failed
make[2]: *** [bin/BasicApp] Error 1
make[2]: Leaving directory '/build'
CMakeFiles/Makefile2:1244: recipe for target 'src/CMakeFiles/BasicApp.dir/all' failed
make[1]: *** [src/CMakeFiles/BasicApp.dir/all] Error 2
make[1]: Leaving directory '/build'
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
I'm assuming that some configuration set in the cinder cmake files is messing things up, but I don't understand why or how to fix it.
This is with gcc version 5.4.0 and cmake version 3.5.1.
Here is a reduced cmake file that has this issue:
cmake_minimum_required(VERSION 3.2)
project(segslam C CXX)
set(CMAKE_CXX_STANDARD 11)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/poco")
find_package(Poco REQUIRED)
#include($ENV{CINDER_PATH}/proj/cmake/configure.cmake)
#set(cinder_DIR $ENV{CINDER_PATH}/${CINDER_LIB_DIRECTORY})
#find_package(cinder REQUIRED PATHS " $ENV{CINDER_PATH}/${CINDER_LIB_DIRECTORY}")
add_executable(BasicApp BasicApp.cpp)
#target_include_directories(BasicApp PUBLIC $ENV{CINDER_PATH}/include)
#target_link_libraries(BasicApp cinder)
target_link_libraries(BasicApp ${Poco_LIBRARIES})
set_target_properties(BasicApp PROPERTIES
DEBUG_POSTFIX "d"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
install(TARGETS BasicApp RUNTIME DESTINATION bin COMPONENT main)
install(FILES ${srcs} DESTINATION app COMPONENT main)
If the commented lines are uncommented, it links in cinder and things break. I'm using a FindPoco.cmake file from here. The cinder cmake files are located here.
It doesn't seem to matter what the linking order is, and none of the other libraries I'm using have this issue.
So it turns out that the issue is an ABI mismatch. Cinder ships with precompiled boost libraries that use a gcc version <5.1, which will cause conflicts if you try to use libraries that have been compiled with gcc version >= 5.1.
My fix was to remove the cinder precompiled boost libraries and recompile with the version of boost in the ubuntu repos.
See this thread on the cinder discourse for more info.

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".