[英]Undefined symbol _main when trying to build shared library g++ / mac
I am trying to build libdecodeqr on a mac. 我想在mac上构建libdecodeqr。 My c++ building and linking history is all on windows, so it's an exciting journey of discovery.
我的c ++构建和链接历史都在windows上,所以这是一个令人兴奋的发现之旅。
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. 我的印象是使用-shared标志创建一个库意味着我不需要主函数。 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. 只是为了踢,我将int main(){return 0;}添加到其中一个cpp文件并重建。 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? 还有什么我需要传递给g ++来告诉它构建一个库吗?
-shared
is not supported on OSX. -shared
不支持OSX。 Use either -dynamiclib
or -bundle
(depending on which type of shared library you want to create). 使用
-dynamiclib
或-bundle
(取决于您要创建的共享库类型)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.