tags:

views:

916

answers:

1

I am trying to build libdecodeqr on a mac. My c++ building and linking history is all on windows, so it's an exciting journey of discovery.

I have finally got to the point where I want to create the linked library. The command I am running is:

g++ -shared -o libdecodeqr.so.0.9.3 bitstream.o codedata.o container.o ecidecoder.o formatinfo.o galois.o imagereader.o libdecodeqr.o -L/opt/local/lib -arch i386 -lcxcore -lcv

The result is:

Undefined symbols:
    "_main", referenced from:
       start in crt1.10.5.o

I was under the impression that a creating a library using -shared flag meant I shouldn't need a main function. There certainly isn't one in the source code.

Just for kicks I added int main() {return 0;} to one of the cpp files and rebuilt. The whole thing compiled and linked, but when I tried to use the output as a library I got errors telling me that I can't link to a main executable. That makes sense I guess.

Is there something else I need to pass to g++ to tell it to build a library?

+3  A: 

-shared is not supported on OSX. Use either -dynamiclib or -bundle (depending on which type of shared library you want to create).

Martin v. Löwis
Perfect, thank you.
Gareth Simpson