Cygwin GCC Associated with Visual Studio Library

I created a simple library (static 64 bit -.lib) using Visual Studio 2012 Express. This whole library has one function:

int get_number()
{ 
    return 67; 
}

Say the lib created is called NumTestLib64.lib.

I am trying to compile a simple program (let it be called test.cpp) with Cygwin64, which will link NumTestLib64.liband print the result get_number():

#include <stdio.h>   

int get_number();

int main()
{
    printf("get_number: %d\n", get_number());
    return 0;
}

Pretty simple? Obviously not.
Compiling with g++ -o test test.cpp -L. -lTestLibStatic64returns:

/tmp/ccT57qc6.o:test.cpp:(.text+0xe): undefined reference to `get_number()'
/tmp/ccT57qc6.o:test.cpp:(.text+0xe): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `get_number()'
collect2: error: ld returned 1 exit status

and g++ -o test test.cpp TestLibStatic64.libreturns:

/tmp/ccMY8yNi.o:test.cpp:(.text+0xe): undefined reference to `get_number()'
/tmp/ccMY8yNi.o:test.cpp:(.text+0xe): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `get_number()'
collect2: error: ld returned 1 exit status

I am looking for the brave who can provide instructions, both on the side of Visual Studio and on the command line side of Cygwin, on how to do this.

-, , , , . DLL , , , , .

, !

+4
1

! *.dll *.lib. *.lib , . DLL (onlty DLL Visual Studio, ):

#ifdef TESTLIB_EXPORTS
#define TESTLIB_API __declspec(dllexport)
#else
#define TESTLIB_API __declspec(dllimport)
#endif

#ifdef __cplusplus
extern "C"
{
#endif

TESTLIB_API int get_num();

#ifdef __cplusplus
}
#endif

, TESTLIB_EXPORTS DLL. , , DLL, - __declspec(dllimport). , extern "C" , , . , Cygwin32 MinGW32, Cygwin64.

+2

Source: https://habr.com/ru/post/1545984/


All Articles