libtool
[Top][All Lists]
Advanced

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

global_symbol_pipe not picking up an initialized global variable with ms


From: David Byron
Subject: global_symbol_pipe not picking up an initialized global variable with msvc
Date: Fri, 14 Aug 2009 14:41:44 -0700

I'm pretty sure I'm running into a pr-msvc-support-specific problem but I'm
still learning about libtool so...

I'm trying to get rid of unresolved externs when linked an executable
against a libtool shared library compiled with msvc.  The unresolved externs
are global variables.  The code in question yet another getopt
implementation.  The variables are declared and defined like this:

<getopt.h>
extern UTL_EXPORT int   opterr;
extern UTL_EXPORT int   optind;
extern UTL_EXPORT int   optopt;
extern UTL_EXPORT int   optreset;
extern UTL_EXPORT char  *optarg;

<getopt_long.c>
int     opterr = 1;
int     optind = 1;
int     optopt = '?';
int     optreset;
char    *optarg;

UTL_EXPORT becomes __declspec(dllexport) when compiling the shared lib,
__declspec(dllimport) when compiling the executable that uses it.

What's interesting is that I only get unresolved externs for the initialized
variables:

utils-test.obj : error LNK2001: unresolved external symbol _optopt
utils-test.obj : error LNK2001: unresolved external symbol _optind
utils-test.obj : error LNK2001: unresolved external symbol _opterr

Snippets from dumpbin -symbols on the getopt_long.obj look like this:

COFF SYMBOL TABLE
000 006DC627 ABS    notype       Static       | @comp.id
001 00000001 ABS    notype       Static       | @feat.00
002 00000000 SECT1  notype       Static       | .drectve
    Section length   C9, #relocs    0, #linenums    0, checksum        0
004 00000000 SECT2  notype       Static       | .debug$S
    Section length 1EEC, #relocs   5B, #linenums    0, checksum        0
006 00000000 SECT3  notype       Static       | .bss
    Section length    7, #relocs    0, #linenums    0, checksum        0
008 00000000 SECT3  notype       Static       | $SG6258
009 00000004 UNDEF  notype       External     | _optarg
00A 00000004 UNDEF  notype       External     | _optreset
00B 00000000 SECT4  notype       Static       | .data
    Section length   44, #relocs    1, #linenums    0, checksum 2C7EE1AD
00D 00000000 SECT4  notype       External     | _opterr
00E 00000004 SECT4  notype       External     | _optind
00F 00000008 SECT4  notype       External     | _optopt
010 0000000C SECT4  notype       Static       | _place

Note that the unitialized variables are marked as "UNDEF" whereas optopt,
optind and optopt are marked as "SECT4".

After a bit of digging, I have a feeling that the place to fix this is the
source file that puts this in the generated libtool script:

# Take the output of nm and produce a listing of raw symbols and C names.
global_symbol_pipe="gawk '     {last_section=section; section=\$ 3};
/Section length .*#relocs.*(pick any)/{hide[last_section]=1};     \$
0!~/External *\\|/{next};     / 0+ UNDEF /{next}; / UNDEF
\\([^|]\\)*()/{next};     {if(hide[section]) next};     {f=0}; \$
0~/\\(\\).*\\|/{f=1}; {printf f ? \"T \" : \"D \"};     {split(\$ 0, a,
/\\||\\r/); split(a[2], s)};     s[1]~/address@hidden/{print s[1], s[1]; next};
s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}     '
prfx=^_"

My libtool/awk skills are not where they need to be to fix this.  My
understanding of symbol resolution/linking in general is not where it needs
to be to even know if pulling in everything marked "External" but not
necessarily "UNDEF" is the right thing to do.

I could (obviously) use a hand here.

Thanks for your help.

$ cl
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for
80x86

$ link
Microsoft (R) Incremental Linker Version 8.00.50727.762

$ libtool --version
libtool (GNU libtool 1.3107 2009-03-20) 2.2.7a

relevant args to configure (run from msys):

$ ../configure CC=cl CXX=cl CPPFLAGS=-D_CRT_SECURE_NO_WARNINGS CFLAGS=-W3
-Zc:wchar_t- -Zi -Od -MDd CXXFLAGS=-W3 -EHsc -Zc:wchar_t- -Zi -Od -MDd
LD=link LDFLAGS=-DEBUG NM=dumpbin -symbols AR=lib STRIP=: RANLIB=:

-DB





reply via email to

[Prev in Thread] Current Thread [Next in Thread]