[freetds] Noobie, please help!
James K. Lowden
jklowden at freetds.org
Mon Mar 9 11:14:54 EDT 2009
Gal Rubinstein wrote:
> g++.exe ../common.o ../t0001.o -o "t0001.exe" -L"C:/MinGW/lib"
> -L"C:/Dev-Cpp/lib" -L"C:/Gal/tmp/freetds-0.82/win32/dev-cpp" -lkernel32
> -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32
> -loleaut32 -luuid ../../../../win32/dev-cpp/libFreeTDS.a
> ../common.o:common.c:(.text+0xa4): undefined reference to `tds_basename'
> ../common.o:common.c:(.text+0x5d7): undefined reference to
> `dbgetuserdata' ../common.o:common.c:(.text+0x797): undefined reference
> to `dbgetuserdata' ../common.o:common.c:(.text+0x867): undefined
> reference to `dbdead' ../t0001.o:t0001.c:(.text+0x88): undefined
> reference to `dbinit'
OK, that's actually pretty good. All you need to do is tell the linker
about the db-lib dynamic library you want to use.
You'll have to fill me in here. What is the name of the db-lib file in
this environment? And what kind of a file is libFreeTDS.a?
In a unixy environment, the static linker resolves a library's symbols
from the .so. That is, the static linker uses a copy of the .so that will
be available at runtime to verify that the .so contains all the symbols
needed be the executable.
In Win32, those jobs are divided: an "import library" (.lib) describes the
.dll to the static linker. You "link" the .lib when building, and at
runtime the, um, runtime linker loads the matching DLL.
The basic question is: How does one tell g++.exe about a DLL that the
executable will use at runtime? I don't know what g++.exe produces when
you're done building what's in src/dblib, i.e., the name of the DLL and
import library, if any. I would guess it produces a .dll and no .lib, and
that the .dll (not the .a) needs to be mentioned when linking the
executable (e.g. t0001.exe).
You use two arguments to tell the linker about any library, static or
dynamic: -L for its location, and -l for its name. If the DLL is
C:/Gal/tmp/freetds-0.82/win32/dev-cpp/FreeTDS.DLL, then, if my guess is
Answer the basic question, and you're nearly home. The only other gotcha
is you'll need some stuff from src/replacements, specifically
tds_basename(). I don't know if the project you're using produces a
dynamic or static library for replacements. I hope it's static. You'll
need to add that to your linker command, too.
BTW, you can drop some of the other libraries you're linking to, at least
for simple things like t0001.exe. For instance, I doubt gdi32 or comdlg32
are needed. Adding them is no harm, but reducing the linker command to
its minimum helps clarify what's happening.
More information about the FreeTDS