cmake not including /usr/local/opt/openssl/lib - xcode

though I do
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
include_directories(/usr/local/opt/openssl/include)
link_directories(/usr/local/opt/openssl/lib)
target_link_libraries(${PROJECT_NAME} ssl crypto)
the cmake generated compiler command doesn't have -L/usr/local/opt/openssl/lib and linker is terminated by
ld: library not found for -lssl
the /usr/local/opt/openssl/lib do has the libssl.dylib. Does cmake deliberately avoiding it in favour of Apples's ssl library?

Related

How do I get CMake to find OpenMP_C, OpenMP_CXX, etc.?

I am fairly new to working with the terminal and I am attempting to use cmake to configure a build for a project that involves public transportation routes. When I attempt to make the build I get the following response in the terminal:
$ cmake ..
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
CMake Warning at CMakeLists.txt:33 (message):
Configuring without OpenMP!
CMake Error at src/CMakeLists.txt:13 (add_subdirectory):
The source directory
/Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/src/cppgtfs
does not contain a CMakeLists.txt file.
CMake Error at src/CMakeLists.txt:14 (add_subdirectory):
The source directory
/Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/src/configparser
does not contain a CMakeLists.txt file.
-- Configuring incomplete, errors occurred!
See also "/Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/build/CMakeFiles/CMakeOutput.log".
See also "/Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/build/CMakeFiles/CMakeError.log".
Below is what I believe to be the relevant code from the CMakeLists.txt file:
find_package(OpenMP)
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
# set compiler flags, see http://stackoverflow.com/questions/7724569/debug-vs-release-in-cmake
if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "-fopenmp -Ofast -fno-signed-zeros -fno-trapping-math -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2 -Wextra -Wno-implicit-fallthrough -pedantic")
else()
message(WARNING "Configuring without OpenMP!")
set(CMAKE_CXX_FLAGS "-Ofast -fno-signed-zeros -fno-trapping-math -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2 -Wextra -Wno-implicit-fallthrough -pedantic")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DLOGLEVEL=3 -DPFAEDLE_DBG=1")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DLOGLEVEL=2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DLOGLEVEL=2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -g -DLOGLEVEL=3")
I have found some similar questions on this and other websites, but I am still struggling to understand the problem because I have never used cmake before and, as mentioned, I am somewhat new to working with the terminal. I would be extremely grateful for any information on what the error messages are actually telling me, or any suggestions on steps I could take/things I could try to solve the issue. I am working on a Mac, if anyone is wondering.
For the compiler to see OpenMP, you may need to set the following options in your cmake command (for dependencies located in /opt/local):
cmake .. \
-DOpenMP_C_FLAGS=-fopenmp=lomp \
-DOpenMP_CXX_FLAGS=-fopenmp=lomp \
-DOpenMP_C_LIB_NAMES="libomp" \
-DOpenMP_CXX_LIB_NAMES="libomp" \
-DOpenMP_libomp_LIBRARY="/opt/local/lib/libomp.dylib" \
-DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp /opt/local/lib/libomp.dylib -I/opt/local/include" \
-DOpenMP_CXX_LIB_NAMES="libomp" \
-DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp /opt/local/lib/libomp.dylib -I/opt/local/include"
The two missing CMakeLists.txt are located in git submodules within src/ To download the submodules, cd to the root phaedle directory and issue the following command:
git submodule update --init --recursive
Edit: this is now fixed in master.

How to disable warnings of gcc compiler both in header and source files?

How to disable warnings of GCC compiler both in header and source files?
In main CMakeLisits.txt:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++ -std=c++11")
...
add_subdirectory(lib)
In lib CMakeLisits.txt:
set(lib_SOURCES
...)
include_directories(${lib_SOURCE_DIR}/include ${lib_BINARY_DIR}/include)
add_library(ilib STATIC ${ilib_EXTRA_CFLAGS} ${ilib_SOURCES})
...
..
I've tried add in lib CMakeLists.txt
include_directories(SYSTEM ${lib_SOURCE_DIR}/include ${lib_BINARY_DIR}/include)
and it helped with headers, but I still have warnings in *.cpp files
Then I tried
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-effc++")
in lib, CMakeLists.txt, and warnings in header appeared again
Don't understand what's happening
CMake version 2.8.12.2
gcc version 4.9.3

osx and clion, can't find omp.h

How do I convince cmake (within CLion) I have the OpenMP headers available? I am trying to compile this project SCD and I receive the following error
...
[ 15%] Building CXX object tools/selector/CMakeFiles/selector.dir/source/main.cpp.o
[ 18%] Building CXX object tools/cc/CMakeFiles/cc.dir/source/main.cpp.o
/Users/buddha/github/buddha314/SCD/tools/wcc/source/main.cpp:22:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
The CMakeLists.txt includes
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -pg -fopenmp -DPROFILE ")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fopenmp -DNDEBUG")
I think that your problem is not specific to CLion but the tool that is used for the building process (i.e CMake) . As already mentioned in this answer, there is a standard module for testing if the compiler supports OpenMP:
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()

How to build dylib in XCode?

I have a library in source code, it builds in .a static library, but i need .dylib. So, i choose Mach-O-Type in "Build Settings" as "Dynamic Library", but get error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/abc/Library/Developer/Xcode/DerivedData/mylib-fwducbhnvcuzuzaopjfimtlylztm/Build/Products/Debug -filelist /Users/abc/Library/Developer/Xcode/DerivedData/mylib-fwducbhnvcuzuzaopjfimtlylztm/Build/Intermediates/mylib.build/Debug/mylib-osx.build/Objects-normal/x86_64/mylib-osx.LinkFileList -fobjc-link-runtime -framework Foundation -o /Users/abc/Library/Developer/Xcode/DerivedData/mylib-fwducbhnvcuzuzaopjfimtlylztm/Build/Products/Debug/libmylib-osx.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `f' in: -fobjc-link-runtime
libtool for some reason uses "-static" instead "-dynamic" flag... Compatibility version i've set. What do you think could be wrong?
object files (.o) could be extracted from archive file (.a) and then packed in .dylib with libtool or gcc

"ld: unknown option: -soname" on OS X

I try to build my app with CMake on Mac OS X, I get the following error:
Linking CXX shared library libsml.so
ld: unknown option: -soname
collect2: ld returned 1 exit status
make[2]: *** [libsml.so] Error 1
make[1]: *** [CMakeFiles/sml.dir/all] Error 2
make: *** [all] Error 2
This is strange, as Mac has .dylib extension instead of .so.
There's my CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
PROJECT (SilentMedia)
SET(SourcePath src/libsml)
IF (DEFINED OSS)
SET(OSS_src
${SourcePath}/Media/Audio/SoundSystem/OSS/DSP/DSP.cpp
${SourcePath}/Media/Audio/SoundSystem/OSS/Mixer/Mixer.cpp
)
ENDIF(DEFINED OSS)
IF (DEFINED ALSA)
SET(ALSA_src
${SourcePath}/Media/Audio/SoundSystem/ALSA/DSP/DSP.cpp
${SourcePath}/Media/Audio/SoundSystem/ALSA/Mixer/Mixer.cpp
)
ENDIF(DEFINED ALSA)
SET(SilentMedia_src
${SourcePath}/Utils/Base64/Base64.cpp
${SourcePath}/Utils/String/String.cpp
${SourcePath}/Utils/Random/Random.cpp
${SourcePath}/Media/Container/FileLoader.cpp
${SourcePath}/Media/Container/OGG/OGG.cpp
${SourcePath}/Media/PlayList/XSPF/XSPF.cpp
${SourcePath}/Media/PlayList/XSPF/libXSPF.cpp
${SourcePath}/Media/PlayList/PlayList.cpp
${OSS_src}
${ALSA_src}
${SourcePath}/Media/Audio/Audio.cpp
${SourcePath}/Media/Audio/AudioInfo.cpp
${SourcePath}/Media/Audio/AudioProxy.cpp
${SourcePath}/Media/Audio/SoundSystem/SoundSystem.cpp
${SourcePath}/Media/Audio/SoundSystem/libao/AO.cpp
${SourcePath}/Media/Audio/Codec/WAV/WAV.cpp
${SourcePath}/Media/Audio/Codec/Vorbis/Vorbis.cpp
${SourcePath}/Media/Audio/Codec/WavPack/WavPack.cpp
${SourcePath}/Media/Audio/Codec/FLAC/FLAC.cpp
)
SET(SilentMedia_LINKED_LIBRARY
sml
vorbisfile
FLAC++
wavpack
ao
#asound
boost_thread-mt
boost_filesystem-mt
xspf
gtest
)
INCLUDE_DIRECTORIES(
/usr/include
/usr/local/include
/usr/include/c++/4.4
/Users/alex/Downloads/boost_1_45_0
${SilentMedia_SOURCE_DIR}/src
${SilentMedia_SOURCE_DIR}/${SourcePath}
)
#link_directories(
# /usr/lib
# /usr/local/lib
# /Users/alex/Downloads/boost_1_45_0/stage/lib
#)
IF(LibraryType STREQUAL "static")
ADD_LIBRARY(sml-static STATIC ${SilentMedia_src})
# rename library from libsml-static.a => libsml.a
SET_TARGET_PROPERTIES(sml-static PROPERTIES OUTPUT_NAME "sml")
SET_TARGET_PROPERTIES(sml-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ELSEIF(LibraryType STREQUAL "shared")
ADD_LIBRARY(sml SHARED ${SilentMedia_src})
# change compile optimization/debug flags # -Werror -pedantic
IF(BuildType STREQUAL "Debug")
SET_TARGET_PROPERTIES(sml PROPERTIES COMPILE_FLAGS "-pipe -Wall -W -ggdb")
ELSEIF(BuildType STREQUAL "Release")
SET_TARGET_PROPERTIES(sml PROPERTIES COMPILE_FLAGS "-pipe -Wall -W -O3 -fomit-frame-pointer")
ENDIF()
SET_TARGET_PROPERTIES(sml PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ENDIF()
### TEST ###
IF(Test STREQUAL "true")
ADD_EXECUTABLE (bin/TestXSPF ${SourcePath}/Test/Media/PlayLists/XSPF/TestXSPF.cpp)
TARGET_LINK_LIBRARIES (bin/TestXSPF ${SilentMedia_LINKED_LIBRARY})
ADD_EXECUTABLE (bin/test1 ${SourcePath}/Test/test.cpp)
TARGET_LINK_LIBRARIES (bin/test1 ${SilentMedia_LINKED_LIBRARY})
ADD_EXECUTABLE (bin/TestFileLoader ${SourcePath}/Test/Media/Container/FileLoader/TestFileLoader.cpp)
TARGET_LINK_LIBRARIES (bin/TestFileLoader ${SilentMedia_LINKED_LIBRARY})
ADD_EXECUTABLE (bin/testMixer ${SourcePath}/Test/testMixer.cpp)
TARGET_LINK_LIBRARIES (bin/testMixer ${SilentMedia_LINKED_LIBRARY})
ENDIF (Test STREQUAL "true")
### TEST ###
ADD_CUSTOM_TARGET(doc COMMAND doxygen ${SilentMedia_SOURCE_DIR}/doc/Doxyfile)
There was no error on Linux.
Build process:
cmake -D BuildType=Debug -D LibraryType=shared .
make
I found, that incorrect command generate in CMakeFiles/sml.dir/link.txt. But why, as the goal of CMake is cross-platforming..
How to fix it?
I had a similar issue on OS X which I resolved using the the install_name switch instead of soname.
gcc -shared <files> -lc -Wl,-install_name,<libname>.so, -o <libname>.so.1
You cleared you're problem, but I wanted to provide this a s a reference for future visitors because there's a bit more to creating a dynamic library on OS X. Also see Creating Dynamic Libraries in the Apple Developer pages.
OS X does not use the convention libcoolstuff.so.X.Y.Z. OS X uses the convention libcoolstuff.X.dylib. The, to embed X.Y.Z into the library, use -install_name, -current_version and -compatibility_version.
I don't know Cmake, but here's how it looks under Make. Your recipe to build the libcoolstuff 1.0.6 will look like:
libcoolstuff libcoolstuff.dylib:
$(CC) $(CFLAGS) -dynamiclib -install_name "libcoolstuff.1.dylib" \
-current_version 1.0.6 -compatibility_version 1.0 -o libcoolstuff.1.dylib $(OBJS)
And your make install rule would look like:
PREFIX?=/usr/local
LIBDIR?=$(PREFIX)/lib
...
install:
cp -f libcoolstuff.1.dylib $(LIBDIR)/libcoolstuff.1.dylib
rm -f $(LIBDIR)/libcoolstuff.dylib
ln -s $(LIBDIR)/libcoolstuff.1.dylib $(LIBDIR)/libcoolstuff.dylib
install_name_tool -change "libcoolstuff.1.dylib" "$(LIBDIR)/libcoolstuff.1.dylib" $(LIBDIR)/libcoolstuff.1.dylib
Under otool, it looks like:
$ otool -L libcoolstuff.dylib
libcoolstuff.dylib:
libcoolstuff.1.dylib (compatibility version 1.0.0, current version 1.0.6)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.7)
Finally, you would use it as expected:
export CFLAGS="-NDEBUG -g2 -O2 -Wall -arch ppc -arch ppc64"
make
...
OK, I found where problem was. Before build, you have to remove all CMake temp folders and files, e.g. CMakeFiles, CMakeCache.txt, Makefile. As in my case, issue was that I built that project on Linux and didn't delete these files...
That's why there's .so extension...
Had a problem with this myself. What fixed it for me was removing the commas and replacing -soname with -install_name

Resources