Pregunta

I am trying to build this library under Mac OS X Lion, gcc4.8, XCode 5.0.2:

https://github.com/zeromq/zmqpp

I built gcc4.8 with:

brew install gcc48 --enable-all-languages

When I try to build it, the linker (in /usr/bin) gives these errors:

$ make
mkdir -p build/max-g++/obj/zmqpp/
g++   -MMD -std=c++0x -pipe -Wall -fPIC -DBUILD_ENV=max -DBUILD_VERSION='"3.2.0"' -DBUILD_VERSION_MAJOR=3 -DBUILD_VERSION_MINOR=2 -DBUILD_VERSION_REVISION=0 -DBUILD_DATESTAMP='"2014-05-13 07:14"' -DBUILD_LIBRARY_NAME='"zmqpp"' -DBUILD_CLIENT_NAME='"zmqpp"' -I./src -O3 -funroll-loops -ffast-math -finline-functions -fomit-frame-pointer -DNDEBUG -c -o build/max-g++/obj/zmqpp/context.o src/zmqpp/context.cpp
mkdir -p build/max-g++/obj/zmqpp/
g++   -MMD -std=c++0x -pipe -Wall -fPIC -DBUILD_ENV=max -DBUILD_VERSION='"3.2.0"' -DBUILD_VERSION_MAJOR=3 -DBUILD_VERSION_MINOR=2 -DBUILD_VERSION_REVISION=0 -DBUILD_DATESTAMP='"2014-05-13 07:14"' -DBUILD_LIBRARY_NAME='"zmqpp"' -DBUILD_CLIENT_NAME='"zmqpp"' -I./src -O3 -funroll-loops -ffast-math -finline-functions -fomit-frame-pointer -DNDEBUG -c -o build/max-g++/obj/zmqpp/frame.o src/zmqpp/frame.cpp
mkdir -p build/max-g++/obj/zmqpp/
g++   -MMD -std=c++0x -pipe -Wall -fPIC -DBUILD_ENV=max -DBUILD_VERSION='"3.2.0"' -DBUILD_VERSION_MAJOR=3 -DBUILD_VERSION_MINOR=2 -DBUILD_VERSION_REVISION=0 -DBUILD_DATESTAMP='"2014-05-13 07:14"' -DBUILD_LIBRARY_NAME='"zmqpp"' -DBUILD_CLIENT_NAME='"zmqpp"' -I./src -O3 -funroll-loops -ffast-math -finline-functions -fomit-frame-pointer -DNDEBUG -c -o build/max-g++/obj/zmqpp/message.o src/zmqpp/message.cpp
mkdir -p build/max-g++/obj/zmqpp/
g++   -MMD -std=c++0x -pipe -Wall -fPIC -DBUILD_ENV=max -DBUILD_VERSION='"3.2.0"' -DBUILD_VERSION_MAJOR=3 -DBUILD_VERSION_MINOR=2 -DBUILD_VERSION_REVISION=0 -DBUILD_DATESTAMP='"2014-05-13 07:14"' -DBUILD_LIBRARY_NAME='"zmqpp"' -DBUILD_CLIENT_NAME='"zmqpp"' -I./src -O3 -funroll-loops -ffast-math -finline-functions -fomit-frame-pointer -DNDEBUG -c -o build/max-g++/obj/zmqpp/poller.o src/zmqpp/poller.cpp
mkdir -p build/max-g++/obj/zmqpp/
g++   -MMD -std=c++0x -pipe -Wall -fPIC -DBUILD_ENV=max -DBUILD_VERSION='"3.2.0"' -DBUILD_VERSION_MAJOR=3 -DBUILD_VERSION_MINOR=2 -DBUILD_VERSION_REVISION=0 -DBUILD_DATESTAMP='"2014-05-13 07:14"' -DBUILD_LIBRARY_NAME='"zmqpp"' -DBUILD_CLIENT_NAME='"zmqpp"' -I./src -O3 -funroll-loops -ffast-math -finline-functions -fomit-frame-pointer -DNDEBUG -c -o build/max-g++/obj/zmqpp/socket.o src/zmqpp/socket.cpp
mkdir -p build/max-g++/obj/zmqpp/
g++   -MMD -std=c++0x -pipe -Wall -fPIC -DBUILD_ENV=max -DBUILD_VERSION='"3.2.0"' -DBUILD_VERSION_MAJOR=3 -DBUILD_VERSION_MINOR=2 -DBUILD_VERSION_REVISION=0 -DBUILD_DATESTAMP='"2014-05-13 07:14"' -DBUILD_LIBRARY_NAME='"zmqpp"' -DBUILD_CLIENT_NAME='"zmqpp"' -I./src -O3 -funroll-loops -ffast-math -finline-functions -fomit-frame-pointer -DNDEBUG -c -o build/max-g++/obj/zmqpp/zmqpp.o src/zmqpp/zmqpp.cpp
g++  -shared -dynamic -Wl,libzmqpp.so.3 -o ./build/max-g++/libzmqpp.so.3 build/max-g++/obj/zmqpp/context.o build/max-g++/obj/zmqpp/frame.o build/max-g++/obj/zmqpp/message.o build/max-g++/obj/zmqpp/poller.o build/max-g++/obj/zmqpp/socket.o build/max-g++/obj/zmqpp/zmqpp.o  -lzmq
ld: file not found: libzmqpp.so.3
collect2: error: ld returned 1 exit status
make: *** [libzmqpp.so] Error 1

So I removed the r in front of dynamic so that it just reads

-dynamic

That seems to be ok. However, then I get

Mac-mini:zmqpp ivan$ make
g++  -shared -dynamic -Wl,-soname -Wl,libzmqpp.so.3 -o ./build/max-g++/libzmqpp.so.3 build/max-g++/obj/zmqpp/context.o build/max-g++/obj/zmqpp/frame.o build/max-g++/obj/zmqpp/message.o build/max-g++/obj/zmqpp/poller.o build/max-g++/obj/zmqpp/socket.o build/max-g++/obj/zmqpp/zmqpp.o  -lzmq
ld: unknown option: -soname
collect2: error: ld returned 1 exit status
make: *** [libzmqpp.so] Error 1

I don't know how to get rid of this error. If I just remove -soname from the Makefile, I get

Mac-mini:zmqpp ivan$ make
g++  -shared -dynamic -Wl,libzmqpp.so.3 -o ./build/max-g++/libzmqpp.so.3 build/max-g++/obj/zmqpp/context.o build/max-g++/obj/zmqpp/frame.o build/max-g++/obj/zmqpp/message.o build/max-g++/obj/zmqpp/poller.o build/max-g++/obj/zmqpp/socket.o build/max-g++/obj/zmqpp/zmqpp.o  -lzmq
ld: file not found: libzmqpp.so.3
collect2: error: ld returned 1 exit status
make: *** [libzmqpp.so] Error 1

libzmqpp.so.3 doen't even look like correct protocol for Mac dynamic libraries.

If I remove the entire line and replace it I get

Mac-mini:zmqpp ivan$ make
g++  -shared -dynamic -o ./build/max-g++/libzmqpp.so.3 build/max-g++/obj/zmqpp/context.o build/max-g++/obj/zmqpp/frame.o build/max-g++/obj/zmqpp/message.o build/max-g++/obj/zmqpp/poller.o build/max-g++/obj/zmqpp/socket.o build/max-g++/obj/zmqpp/zmqpp.o  -lzmq
ar crf ./build/max-g++/libzmqpp.a build/max-g++/obj/zmqpp/context.o build/max-g++/obj/zmqpp/frame.o build/max-g++/obj/zmqpp/message.o build/max-g++/obj/zmqpp/poller.o build/max-g++/obj/zmqpp/socket.o build/max-g++/obj/zmqpp/zmqpp.o
ar: illegal option -- f
usage:  ar -d [-TLsv] archive file ...
    ar -m [-TLsv] archive file ...
    ar -m [-abiTLsv] position archive file ...
    ar -p [-TLsv] archive [file ...]
    ar -q [-cTLsv] archive file ...
    ar -r [-cuTLsv] archive file ...
    ar -r [-abciuTLsv] position archive file ...
    ar -t [-TLsv] archive [file ...]
    ar -x [-ouTLsv] archive [file ...]
make: *** [libzmqpp.a] Error 1

One thing, the ar it is using is the one in /usr/bin not in /usr/local/Cellar/gcc48/4.8.2/bin/gcc, gcc-ar-4.8

¿Fue útil?

Solución

g++ -dynamiclib -Wl,-headerpad_max_install_names,-undefined,dynamic_lookup,-current_version,1.0,-install_name,/usr/local/lib/libzmqpp.3.dylib -o libzmqpp.1.dylib ./build/max-g++/obj/zmqpp/context.o ./build/max-g++/obj/zmqpp/frame.o ./build/max-g++/obj/zmqpp/message.o ./build/max-g++/obj/zmqpp/poller.o ./build/max-g++/obj/zmqpp/socket.o ./build/max-g++/obj/zmqpp/zmqpp.o -lzmq 

According to this question this should work. I would try with and without the -dynamic. I build shared libraries all day long but don't have a mac. I am not sure why it is trying to build a static library with the ar command.

The mac linker doesn't take the arguments the linux ones do. Here is some information on building shared libraries on Mac.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top