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

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

Related

RcppArmadillo Compile Errors on OS X Mavericks

This is a follow-up to the question at Element-Wise Matrix Multiplication in Rcpp
I have been getting a number of different kinds of errors with RcppArmadillo since upgrading to Mavericks. I have Xcode 5.0.2 and Command Line Tools installed. Also, gfortran from Homebrew. But I keep encountering the error below --
> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b)
{ return(a % b); }", depends="RcppArmadillo")
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_18474.so] Error 1
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include - I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/RcppArmadillo/include" -fPIC "-mtune=native -g -O2 -Wall -pedantic -Wconversion" -c fileaf992bfb8f84.cpp -o fileaf992bfb8f84.o clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -L/usr/local/lib -o sourceCpp_18474.so fileaf992bfb8f84.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -lgfortran /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/lib/libRcpp.a -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, :
Error 1 occurred building shared library.
WARNING: The tools required to build C++ code for R were not found.
Please install Command Line Tools for XCode (or equivalent).
# Contents of Makevars
$ cat ~/.R/Makevars
CC=clang
CXX=clang++
CXXFLAGS="-mtune=native -g -O2 -Wall -pedantic -Wconversion"
FLIBS=-lgfortran
Commenting FLIBS=-lgfortran does not help and results in even more error messages --
> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b) { return(a % b); }", depends="RcppArmadillo")
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_50381.so] Error 1
Thanks in advance.
Update
Following suggestions from response from Kevin and Dirk below, I re-installed Rcpp, RcppArmadillo and inline from source and updated FLIBS to point to the actual directory. This solved the issue.
# Update FLIBS in ~/.R/Makevars
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
#Re-Install from source
install.packages(c("Rcpp","RcppArmadillo","inline"),type="source")
#Restart R
EDIT: If you're a Homebrew user, you now instead need to use brew install gcc (gfortran is no longer provided separate of gcc), and you can then follow the instructions here to get set up.
You have to symlink the libraries to /usr/local/lib manually:
ln -s /usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.* /usr/local/lib/
I thought brew link gfortran would handle this, but apparently it only symlinks the gfortran program and not the actual libraries. So, unfortunately, you have to do it yourself.
(Replace 4.8.2 with whichever version of gfortran you're using from homebrew.)
Alternatively, if you want to keep from modifying /usr/local/lib, you can use
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
in your ~/.R/Makevars file instead, so R knows where to find the gfortran libraries.
I can only suggest you study the numerous threads on the r-sig-mac list, the different answers here on SO as well as the posts on the rcpp-devel list.
As your error comes from the failed Fortran linking, maybe also review the standard page by Simon U. as well as the tools page it points too. AFAIK you should use the (older) gfortran 4.2.* from that page with R -- but then I am not an OS X user.
Edit in late 2016: We now have more detailed instructions in section 2.16 of the Rcpp FAQ.

Build Android NDK project with Cmake

I would like to generate my android native application with the android NDK and Cmake, so, I've downloaded the android-cmake toolchain.
Cmake generate my project successfully, but when I try to go in the generate directory and try to run "make", I've got the following error:
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/ldz/Desktop/myProject
[ 1%] Building CXX object Project/src/Main/Core/CMakeFiles/Core.dir/Main/Main.cpp.o
arm-linux-androideabi-g++: error: unrecognized command line option '-stdlib=libc++'
I don't know what is wrong here, my project use C++11, here is my g++ --version result:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.76) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
Thanks!
To build an Android NDK project with Cmake and create APK, you should do :
Instead of using android-cmake, you should use the fork from taka-no-me.
Then use Apk.cmake from pixellight. Copy also [AndroidManifest.xml.in, LoadLibraries.java.in, strings.xml.in] from this repo.
Have a CMakeLists.txt like this :
cmake_minimum_required(VERSION 2.8.3)
project(testBuilder)
include("Apk.cmake" REQUIRED)
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
set(TEST_SRC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
src/Main.cpp
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -ffor-scope -fno-rtti -fno-exceptions -pipe -ffunction-sections -fdata-sections -ffast-math -Wnon-virtual-dtor -Wreorder -Wsign-promo -fvisibility=hidden -fvisibility-inlines-hidden -Wstrict-null-sentinel -Os -funroll-all-loops -fpeel-loops -ftree-vectorize")
set(LINKER_FLAGS "${LINKER_FLAGS} -Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined -Wl,--strip-all -Wl,-rpath-link=${ANDROID_NDK_SYSROOT}/usr/lib/ -L${ANDROID_NDK_SYSROOT}/usr/lib/")
add_library(test SHARED ${TEST_SRC})
target_link_libraries(test log android)
set_target_properties(test PROPERTIES COMPILE_DEFINITIONS "ANDROID")
set(APP_SHARED_LIBRARIES ${LIBRARY_OUTPUT_PATH}/libtest.so)
android_create_apk(test "${CMAKE_BINARY_DIR}/apk" "${APP_SHARED_LIBRARIES}" "" "Data")
This is Main.cpp
#include <android_native_app_glue.h>
#include <android/log.h>
#define APPNAME "TestApp"
void android_main(struct android_app* state)
{
app_dummy(); // Make sure glue isn't stripped
__android_log_print(ANDROID_LOG_INFO, APPNAME, "HolyShit you did it !");
ANativeActivity_finish(state->activity);
}
Based on Vi.:s answer I did a clone of android-cmake on github and added a modified Apk.cmake called android.apk.cmake. I use NativeActivity instead of pixellight:s LoadLibraries.java.
The clone is here:
https://github.com/Discordia/android-cmake
I created the example in Vi.:s answer:
https://github.com/Discordia/android-cmake-example

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

Qt creator -1: error: [CMakeFiles/yahtzee.dir/gamecontroller.cpp.o] Error 1 : File not found

I am using Qt creator 2.5 with CMake (2.8.7) and gcc 4.6.3 and lately I have encountered this strange error :
:-1: error: [CMakeFiles/yahtzee.dir/gamecontroller.cpp.o] Error 1
File not found
What can I do about it ? CMake is not generating this gamecontroller.cpp.o
this is my CMakeLists.txt file
project(cpp_workshop)
cmake_minimum_required(VERSION 2.6)
# Set default compile flags for GCC
if(CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "GCC detected, adding compile flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall -Wextra -Werror")
else()
message(STATUS "GCC not detected, probably running Windows")
endif(CMAKE_COMPILER_IS_GNUCXX)
#add_definitions("-Wall -Werror")
ADD_DEFINITIONS("-Wno-unused-parameter")
add_executable(yahtzee #name of the executable
gamecontroller.h gamecontroller.cpp
player.h player.cpp
game.h game.cpp
dice.h dice.cpp
strategy.cpp strategy.h
istrategy.h
game_rules.h
main singleton
)
And just to mention, all these files are located in directory and this is the 'build' directory that CMake creates :
CMakeCache.txt CMakeFiles cmake_install.cmake cpp_workshop.cbp Makefile
and the above CMakeFiles dir
CMakeCCompiler.cmake CMakeDirectoryInformation.cmake CompilerIdCXX TargetDirectories.txt
cmake.check_cache CMakeOutput.log Makefile2 yahtzee.dir
CMakeCXXCompiler.cmake CMakeSystem.cmake Makefile.cmake
CMakeDetermineCompilerABI_C.bin CMakeTmp Progress
CMakeDetermineCompilerABI_CXX.bin CompilerIdC progress.marks
Ok, the problem was with Cmake's argument passed to gcc
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
I changed that to
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
and now it works. Surprisingly, C++11 does not work with gcc yet ?

Problems installing Haskell library regex-pcre on Mac OS X

I'm trying to install the Haskell regex-pcre library using:
cabal install --extra-include-dirs=/usr/local/include \
--extra-include-dirs=/usr/include regex-pcre
However I get this weird error:
Resolving dependencies...
Configuring regex-pcre-0.94.2...
Preprocessing library regex-pcre-0.94.2...
In file included from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include/HsFFI.h:68,
from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/template-hsc.h:4,
from dist/build/Text/Regex/PCRE/Wrap_hsc_make.c:1:
/usr/include/float.h:8:24: error: float.h: No such file or directory
In file included from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/template-hsc.h:9,
from dist/build/Text/Regex/PCRE/Wrap_hsc_make.c:1:
/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
compiling dist/build/Text/Regex/PCRE/Wrap_hsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c dist/build/Text/Regex/PCRE/Wrap_hsc_make.c -o dist/build/Text/Regex/PCRE/Wrap_hsc_make.o -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -fno-stack-protector -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -fno-stack-protector -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -D__GLASGOW_HASKELL__=700 -Ddarwin_BUILD_OS -Ddarwin_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH -I/usr/include -I/usr/local/include -DHAVE_PCRE_H -DSPLIT_BASE=1 -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/bytestring-0.9.1.10/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/base-4.3.1.0/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include/
cabal: Error: some packages failed to install:
regex-pcre-0.94.2 failed during the building phase. The exception was:
ExitFailure 1
The gist of it, seems to be that it can't find a second float.h file:
/usr/include/float.h:8:24: error: float.h: No such file or directory
I've opened /usr/include/float.h and line 8 reads:
#include_next <float.h>
I've done my searching on Google, and although I don't know that much C I think I understand what that line is supposed to say, but... I don't know how to really solve this problem. I don't know where else I have a float.h file on my system.
The GHC and GCC versions I'm using. GCC comes from XCode 4. GHC is 32bit, but I've tried the 64bit version too, with the same results.
$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.2
OS X version is 10.6.7.
Any help greatly appreciated.
Looks to me like ticket #5011 - XCode 4 on Mac + GHC 7.0.2 fails to link.
This is fixed in GHC 7.0.3 which will be part of the mid-April release of the Haskell Platform.
And alternative fix is to downgrade to the 2010.2 Haskell Platform.
See this question yesterday: Can't install OpenGLRaw-1.1.0.1 on OS X

Resources