Getting winegcc to link with dll. linker input file not used because linking not done, *.o is an empty file

164 Views Asked by At

I am trying to compile some C++ code which uses a Windows dll on Linux using winegcc. The .dll, .lib and some .h files are provided to me but I do not have access to the source code.

I set up a base project following the instructions coming with the library on Windows in Visual Studio to get a feeling for the project itself. Through this I learned that the library appears to be for 32-bit.

The header file to be used with the library includes _declspec(dllexport) and __declspec(dllimport). winegcc did not like that, so I added another underscore each. This leads to winegcc warning me about ignoring those. When using [[gnu::dllimport]] it also ignores that.

I did not find a way to make it not ignore that so I tried turning some other dials instead.

Running winegcc Coursework1.cpp ICS0017DataSource.dll -m32 results in this:

In file included from Coursework1.cpp:9:
ICS0017DataSource.h:15:51: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   15 | LIBSPEC HEADER_B *GetStruct1(int iItem, int nItems);
      |                                                   ^
ICS0017DataSource.h:16:51: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   16 | LIBSPEC HEADER_C *GetStruct2(int iItem, int nItems);
      |                                                   ^
ICS0017DataSource.h:17:52: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   17 | LIBSPEC HEADER_A **GetStruct3(int iItem, int nItems);
      |                                                    ^
ICS0017DataSource.h:18:51: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   18 | LIBSPEC HEADER_D *GetStruct4(int iItem, int nItems);
      |                                                   ^
ICS0017DataSource.h:19:51: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   19 | LIBSPEC HEADER_E *GetStruct5(int iItem, int nItems);
      |                                                   ^
ICS0017DataSource.h:20:53: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   20 | LIBSPEC void *GetItem(int iItem, char *pID = nullptr);
      |                                                     ^
gcc: warning: ICS0017DataSource.dll: linker input file unused because linking not done
winebuild: tmp6511ca03/ICS0017DataSource-00000001.o is an empty file
winegcc: /usr/bin/winebuild failed

winegcc Coursework1.cpp ICS0017DataSource.lib -m32

In file included from Coursework1.cpp:9:
ICS0017DataSource.h:15:51: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   15 | LIBSPEC HEADER_B *GetStruct1(int iItem, int nItems);
      |                                                   ^
ICS0017DataSource.h:16:51: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   16 | LIBSPEC HEADER_C *GetStruct2(int iItem, int nItems);
      |                                                   ^
ICS0017DataSource.h:17:52: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   17 | LIBSPEC HEADER_A **GetStruct3(int iItem, int nItems);
      |                                                    ^
ICS0017DataSource.h:18:51: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   18 | LIBSPEC HEADER_D *GetStruct4(int iItem, int nItems);
      |                                                   ^
ICS0017DataSource.h:19:51: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   19 | LIBSPEC HEADER_E *GetStruct5(int iItem, int nItems);
      |                                                   ^
ICS0017DataSource.h:20:53: warning: ‘gnu::dllimport’ scoped attribute directive ignored [-Wattributes]
   20 | LIBSPEC void *GetItem(int iItem, char *pID = nullptr);
      |                                                     ^
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libm.so when searching for -lm
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libc.so when searching for -lc
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libc.so when searching for -lc
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: tmp6511e54b/Coursework1-00000000.o: in function `main':
Coursework1.cpp:(.text+0x25): undefined reference to `GetStruct2'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: Coursework1.cpp:(.text+0x37): undefined reference to `GetItem'
collect2: error: ld returned 1 exit status
winegcc: /usr/bin/gcc failed

GetStruct2 and GetItem are the functions that are implemented in the dll.

So I decided to try doing the linking seperately: winegcc -c Coursework1.cpp -m32 Only gives warnings about dllimport being ignored.

wineg++ -m32 -o Coursework1 Coursework1.o -lICS0017DataSource

/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: cannot find -lICS0017DataSource: No such file or directory
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libm.so when searching for -lm
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libc.so when searching for -lc
collect2: error: ld returned 1 exit status
winegcc: /usr/bin/g++ failed

This happened also when using gcc and/or defining a path with -L or just -L by itself, it keeps looking for a file that starts with -l …

wineg++ -m32 -o Coursework1 Coursework1.o ICS0017DataSource.lib

/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libm.so when searching for -lm
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libc.so when searching for -lc
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libc.so when searching for -lc
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/bin/../lib64/libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: Coursework1.o: in function `main':
Coursework1.cpp:(.text+0x25): undefined reference to `GetStruct2'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: Coursework1.cpp:(.text+0x37): undefined reference to `GetItem'
collect2: error: ld returned 1 exit status
winegcc: /usr/bin/g++ failed

This was inspired by the way it worked in Visual Studio where the lib file had to be configured to be used somewhere. As that did not work I did a lot more digging and found a post stating that one can also link directly to the dll:

wineg++ -m32 -o Coursework1 Coursework1.o ICS0017DataSource.dll

g++: warning: ICS0017DataSource.dll: linker input file unused because linking not done
winebuild: tmp6511bef3/ICS0017DataSource-00000000.o is an empty file
winegcc: /usr/bin/winebuild failed

This failure seems identical to what happens when using winegcc on the cpp file and the dll.

As by now pretty much all the links I find (for gcc in general, MinGW, as winegcc is supposed to mimic the behaviour of their gcc and winegcc itself) are purple or the same man page on various web pages I turn to you seeking some ideas of how to get this to work.

---Edit---

As pointed out in the comments, GCC is not compatible with the output of microsoft's compiler. Using clang / clang-cl instead works.

0

There are 0 best solutions below