简体   繁体   English

在CYGWIN中为C ++程序创建DLL

[英]To Create a DLL for C++ program in CYGWIN

I am trying to convert an Math.cpp into a dll in Cygwin. 我正在尝试将Math.cpp转换为Cygwin中的dll。 I am trying this code in Cygwin to compile. 我正在Cygwin中尝试将此代码进行编译。

gcc -c Math.cpp

Now am trying to convert the .o in into .dll. 现在正在尝试将.o转换为.dll。 For this I used the below code 为此,我使用了以下代码

gcc -shared -o Math.dll Math.o 

where am getting a huge error message in cygwin which says "Math.o:Math.cpp:(.text+0x55): undefined reference to std::ios_base::Init::Init()' Math.o:Math.cpp:(.text+0x55): relocation truncated to fit: R_X86_64_PC32 against undefined symbol std::ios_base::Init::Init()Math.o:Math.cpp:(.text$_ZN11Mathematics5inputEv[_ZN11Mathematics5inputEv]+0x21): undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)''",etc. 在cygwin中收到一条巨大的错误消息,上面写着“ Math.o:Math.cpp :(。text + 0x55):对std::ios_base::Init::Init()' Math.o:Math.cpp:(.text+0x55): relocation truncated to fit: R_X86_64_PC32 against undefined symbol未定义引用std::ios_base::Init::Init()' Math.o:Math.cpp:(.text+0x55): relocation truncated to fit: R_X86_64_PC32 against undefined symbol std :: ios_base :: Init :: Init()Math.o:Math.cpp :(。text $ _ZN11Mathematics5inputEv [_ZN11Mathematics5inputEv] + 0x21):un0引用`std :: basic_ostream>&std :: operator <<>(std :: basic_ostream>&,char const *)''“等。

In my C++ program namespace is std; 在我的C ++程序中,命名空间是std; class name is Mathematics, there are two methods input() and add() and there is a main method which calls these methods. 类名是Mathematics,有input()和add()两个方法,还有一个主要方法调用这些方法。

Use g++ rather than gcc 使用g++而不是gcc

This will cause gcc to link with the standard C++ libary, which should resolve those symbols. 这将导致gcc与标准C ++库链接,该库应解析这些符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM