Re: Compiling a shared library on windows with undefined symbol

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 27, 2019 at 10:27 AM Rastislav Stanik <gcc@xxxxxxxxxx> wrote:
> I'm trying to compile file "test.c" with gcc 8.1 on Windows. The file
> contains following code:
>
>         __declspec( dllimport ) void foo(void);
>
>         __declspec( dllexport ) void bar(void)
>         {
>                 foo();
>         }
>
> The compilation step works fine:
>         C:\test>gcc -m64 -c test.c -o test.o
>
> The linking step fails:
>         C:\test>gcc -m64 -shared -o Test.dll test.o
>         test.o:test.c:(.text+0xb): undefined reference to `__imp_foo'
>         collect2.exe: error: ld returned 1 exit status
>
> Similar code on Linux works fine and generates a shared library with
> undefined symbol "foo". That is what I want to do on Windows too.
>
> The goal is to create an application that uses Test.dll and also another
> shared library FooLib.dll which _does_ define the "foo()" function - i.e.
> at the dynamic linking step during process creation the symbol _will_ be
> available.

Then Test.dll has to be linked against FooLib.dll (actually
foolib.lib, the import library). That’s just how DLLs work on Windows.
There is no global namespace.

> I would prefer to _not_ add library FooLib to the linking step of Test.dll
> due circular dependencies.

What you describe is not circular.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux