Undefined symbol _main when trying to build shared library g++ / mac

女生的网名这么多〃 提交于 2019-12-19 03:37:10

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/1494407/undefined-symbol-main-when-trying-to-build-shared-library-g-mac

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!