Search code examples
c++cygwin

To Create a DLL for C++ program in CYGWIN


I am trying to convert an Math.cpp into a dll in Cygwin. I am trying this code in Cygwin to compile.

gcc -c Math.cpp

Now am trying to convert the .o in into .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 symbolstd::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.

In my C++ program namespace is std; class name is Mathematics, there are two methods input() and add() and there is a main method which calls these methods.


Solution

  • Use g++ rather than gcc

    This will cause gcc to link with the standard C++ libary, which should resolve those symbols.