[freetds] compiling tsql

James K. Lowden jklowden at freetds.org
Sat May 26 13:49:06 EDT 2007

Tim Goossens wrote:
> Is tsql.o merely build out of tsql.c and the headers files mentioned in
> tsql.c? 

Except for rare #include tricks, a .o file always has one and only one .c

Here's a command line to compile tsql in build/src/apps (a directory you'd
have to create yourself):

	-I. \
	-I../../../src/apps \
	-I../../../include \
	-I../../include \
	-I/usr/pkg/include \
	-DDEBUG=1 \
	-g \
	-O2 \
	-o tsql \
	-static \
	-L/usr/pkg/lib \
	-L../tds/.libs \
	-L../replacements/.libs \
	../../../src/apps/tsql.c \
	-lreadline \
	-ltds \
	-lreplacements \

gcc will compile and link in one step; to compile only (creating tsql.o),
add -c to the above.  

This command links statically.  If you want dynamic linking, you have to
either embed the RPATH in the executable or otherwise tell the runtime
linker where the shared objects are to be found.  

This command uses the configure-generated config.h.  You can trim config.h
considerably, but if you try to do without it altogether, you'll find
tsql.c relies heavily on #if tests for header files and some other
functionality.  You can safely remove readline (readline is why I add
/usr/pkg to my include and link paths).  I think readline is what creates
the dependency on libtermcap, btw.  

> Anyway, I am really grateful for your help and I have learned allot
> reading this list.  

Always a good thing.  You're welcome.  


More information about the FreeTDS mailing list