未定义的符号_main在尝试构建共享库时使用g ++ / mac [英] Undefined symbol _main when trying to build shared library g++ / mac
问题描述
我正在试图在Mac上构建libdecodeqr。我的c ++构建和链接历史都在windows上,所以这是一个令人兴奋的发现之旅。
我终于到了想要创建链接库的地步。我正在运行的命令是:
g ++ -shared -o libdecodeqr.so.0.9.3 bitstream.o codedata.o容器.o ecidecoder.o formatinfo.o galois.o imagereader.o libdecodeqr.o -L / opt / local / lib -arch i386 -lcxcore -lcv
结果是:
$ p $ 未定义符号:
_main,引用自:
开始于crt1.10.5.o
我的印象是,使用-shared标志创建一个库意味着我不应该需要一个主要功能。在源代码中肯定没有一个。
只是为了踢我添加int main(){返回0;}到其中一个cpp文件并重建。整个事情编译和链接,但是当我试图使用输出作为库时,我得到错误告诉我,我不能链接到一个主要的可执行文件。这是有道理的我猜。
有什么我需要传递给g ++来告诉它建立一个库吗?
-shared
在OSX上不受支持。使用 -dynamiclib
或 -bundle
(具体取决于您要创建哪种类型的共享库)。
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?
-shared
is not supported on OSX. Use either -dynamiclib
or -bundle
(depending on which type of shared library you want to create).
这篇关于未定义的符号_main在尝试构建共享库时使用g ++ / mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!