tony_merguez
tony_merguez

Reputation: 371

Use --enable-stdcall-fixup to disable these warnings

I am trying to build a dll in C++ in which I use a C dll with prototypes like : int __stdcall foo();.

When linking, the compiler outputs:

Warning: resolving _foo@0 by linking to _foo 
Use --enable-stdcall-fixup to disable these warnings

so I added the option when linking, the command looks like:

g++ -std=c++0x -o fooLib.dll fooObj.o -lfooClib --enable-stdcall-fixup -shared

but seems like the g++ doesn't know this option: g++.exe: error: unrecognized option '--enable-stdcall-fixup'

when I am adding only -enable-stdcall-fixup (one hyphen), it still shows the warnings (looks like has the option has no effect), and the ouput is kind weird:

g++ -std=c++0x -o fooLib.dll fooObj.o -lfooClib -enable-stdcall-fixup -shared
Warning: resolving _foo@0 by linking to _foo
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
ld.exe: warning: cannot find entry symbol nable-stdcall-fixup; defaulting to 679c1000

so does any body know what I am doing wrong ?

g++ --version
g++ (GCC) 4.6.1

Upvotes: 1

Views: 925

Answers (1)

Daniel Dimijian
Daniel Dimijian

Reputation: 36

Indeed, --enable-stdcall-fixup is not a g++ option. It's a linker option, and you can find it in the ld(1) manpage:

   --enable-stdcall-fixup
   --disable-stdcall-fixup
       If the link finds a symbol that it cannot resolve, it will attempt
       to do "fuzzy linking" by looking for another defined symbol that
       differs only in the format of the symbol name (cdecl vs stdcall)
       and will resolve that symbol by linking to the match.  For example,
       the undefined symbol "_foo" might be linked to the function
       "_foo@12", or the undefined symbol "_bar@16" might be linked to the
       function "_bar".  When the linker does this, it prints a warning,
       since it normally should have failed to link, but sometimes import
       libraries generated from third-party dlls may need this feature to
       be usable.  If you specify --enable-stdcall-fixup, this feature is
       fully enabled and warnings are not printed.  If you specify
       --disable-stdcall-fixup, this feature is disabled and such
       mismatches are considered to be errors.  [This option is specific
       to the i386 PE targeted port of the linker]

gcc is able to recognize some common linker options and pass them on to ld. For example, gcc passes the -llibrary options used to link in library code directly to the linker, as well as an option -e which will be relevant below. Whenever this is the case, it's documented in the gcc(1) manpage.

As you've discovered, this is not the case with --enable-stdcall-fixup, so you'll need to explicitly pass it. In order to pass arbitrary options to the linker, gcc has -Wl. From gcc(1):

   -Wl,option
       Pass option as an option to the linker.  [...]

So in your case, you would call

g++ -Wl,--enable-stdcall-fixup [...]

I don't have the version of the linker mentioned in the manpage, so it still comes up as an unrecognized option for me. But on your system, given that the linker is telling you to use the option, I can only assume it is the version that recognizes it.


As an aside, when you tried calling the option with only one dash, you ran into a red herring. You were actually invoking the -e gcc option that I mentioned above, with the option argument nable-stdcall-fixup. From gcc(1):

   -e entry
   --entry=entry
       Specify that the program entry point is entry.  The argument is
       interpreted by the linker; the GNU linker accepts either a symbol
       name or an address.

So you actually ended up passing an option to the linker saying that, when you execute your program, you want it to begin execution from a function named nable-stdcall-fixup instead of the usual main.

Upvotes: 2

Related Questions