2

I have a project in Visual Stuio 2012 Express and I would like to include a static library, compiled with gcc from MinGW. I included the library i nthe project options of the project.

Not working. Next I tried with a mockup minimal library.

test.c

int foo(){return 5;}

cmd:

gcc -c test.c
ar rcs libtest.a test.o

objdump:

C:\ARM_Workpsace - Legacy\HardwareEmulation\build>objdump -t test.o

test.o:     file format pe-i386

SYMBOL TABLE:
[  0](sec -2)(fl 0x00)(ty   0)(scl 103) (nx 1) 0x00000000 test.c
File
[  2](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 1) 0x00000000 _testfun2
AUX tagndx 0 ttlsiz 0x0 lnnos 0 next 0
[  4](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text
AUX scnlen 0xa nreloc 0 nlnno 0
[  6](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .data
AUX scnlen 0x0 nreloc 0 nlnno 0
[  8](sec  3)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .bss
AUX scnlen 0x0 nreloc 0 nlnno 0
[ 10](sec  4)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .rdata$zzz
AUX scnlen 0x11 nreloc 0 nlnno 0
[ 12](sec  5)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .eh_frame
AUX scnlen 0x38 nreloc 1 nlnno 0

But VS2010 still returns the same error:

1>------ Rebuild All started: Project: ReverbTwo, Configuration: Debug Win32 ------
1>  ReverbTwo.cpp
1>  RackAFXDLL.cpp
1>  pluginobjects.cpp
1>  plugin.cpp
1>  Generating Code...
1>plugin.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>     Creating library C:\Users\user\AppData\Roaming\RackAFX\PlugIns\ReverbTwo.lib and object C:\Users\user\AppData\Roaming\RackAFX\PlugIns\ReverbTwo.exp
1>ReverbTwo.obj : error LNK2019: unresolved external symbol "int __cdecl testfun2(void)" (?testfun2@@YAHXZ) referenced in function "public: __thiscall CReverbTwo::CReverbTwo(void)" (??0CReverbTwo@@QAE@XZ)
1>C:\Users\user\AppData\Roaming\RackAFX\PlugIns\ReverbTwo.dll : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Vorac
  • 8,726
  • 11
  • 58
  • 101
  • Reads like you didn't implement a destructor for the AudioProcessor child class that you created in your project. – iheanyi Mar 04 '15 at 18:22
  • @iheanyi, well, its and abstract base class `virtual ~AudioProcessor() = 0`.` – Vorac Mar 04 '15 at 20:54
  • 2
    Calling code compiled by another compiler is fraught with trouble. The most obvious mistake here is that MSVC++ cannot see that this is a C function, the `extern "C"` attribute is missing. – Hans Passant Mar 06 '15 at 15:42
  • Thanks, @HansPassant. I created an empty `.c` project and imported `libtest.a`; the symbol was found. So now I have a working and a problematic setup and need to bridge the gap. – Vorac Mar 06 '15 at 16:01
  • Just write the .h file so a C++ compiler can use it as well. [Like this](http://stackoverflow.com/a/18288885/17034). – Hans Passant Mar 06 '15 at 16:14
  • Still won't work. There's some extra effort needed to use a MinGW compiled static library with VS. See my answer for details. – iheanyi Mar 06 '15 at 21:23

1 Answers1

1

MinGW has instructions on using MinGW libraries in visual studio projects:

http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs

For reasons why libraries provided by different compilers are not necessarily compatible, see:

http://www.mingw.org/wiki/Interoperability_of_Libraries_Created_by_Different_Compiler_Brands

iheanyi
  • 3,107
  • 2
  • 23
  • 22
  • Thanks for the valuable links (in the meantime I had discovered some of the points the hard way). Unfortunately, *currently I am able to depend only on pure C static libraries*. As soon as I introduce a class in any function implementation, the symbols can no longer be resolved. Everything is wrapped in `extern "C"`. – Vorac Mar 09 '15 at 16:15