Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Building Tcl/Tk as a static library on Windows

0 views
Skip to first unread message

Torsten Mohr

unread,
Dec 28, 2003, 4:32:00 PM12/28/03
to
Hi,

i'd like to build Tcl and Tk as a static library to use it in
own programs as an internal scripting language. I'd like to
build standalone programs that don't need any other DLLs.

Can anybody tell me how to build Tcl and Tk as a static library
on Windows?


Thanks for hints,
Torsten.

Helmut Giese

unread,
Dec 28, 2003, 7:04:29 PM12/28/03
to
On Sun, 28 Dec 2003 22:32:00 +0100, Torsten Mohr <tm...@s.netic.de>
wrote:

Hi Torsten,
just call
make -DSTATIC_BUILD all
I usually add a -B to (re-) build all, so I would use
make -B -DSTATIC_BUILD all
HTH
Helmut Giese

David Gravereaux

unread,
Dec 28, 2003, 7:57:16 PM12/28/03
to
Torsten Mohr <tm...@s.netic.de> wrote:


With VC++ as the compiler, do:

C:\...\tcl_src\win> nmake.exe -f makefile.vc OPTS=static
--
David Gravereaux <davy...@pobox.com>
[species: human; planet: earth,milkyway(western spiral arm),alpha sector]

David Gravereaux

unread,
Dec 28, 2003, 8:18:27 PM12/28/03
to
David Gravereaux <davy...@pobox.com> wrote:

>nmake.exe -f makefile.vc OPTS=static

To use msvcrt instead of libcmt (the default for static), do:

nmake.exe -f makefile.vc OPTS=static,msvcrt

To add threading do:

nmake.exe -f makefile.vc OPTS=static,threads

To add symbols, do:

nmake.exe -f makefile.vc OPTS=static,symbols


More option and instruction are found in makefile.vc itself.

Dennis LaBelle

unread,
Dec 28, 2003, 9:58:42 PM12/28/03
to
David Gravereaux wrote:

> David Gravereaux <davy...@pobox.com> wrote:
>
>>nmake.exe -f makefile.vc OPTS=static
>
> To use msvcrt instead of libcmt (the default for static), do:
>
> nmake.exe -f makefile.vc OPTS=static,msvcrt
>
> To add threading do:
>
> nmake.exe -f makefile.vc OPTS=static,threads
>

You should also make sure that any modules of your own creation are compiled
with the -MT option since the static TCL and TK libraries are compiled with
this "multithreading" option.

Torsten Mohr

unread,
Dec 29, 2003, 6:47:24 PM12/29/03
to
Hi,

thank you all for your very helpful hints. I now have
several LIBs on my system available. But i still have
some questions. These surely come up because i'm not
experienced in Windows programming, but it would be great
if somebody could give me some hints on these.

>> To add threading do:
>>
>> nmake.exe -f makefile.vc OPTS=static,threads
>>
> You should also make sure that any modules of your own creation are
> compiled with the -MT option since the static TCL and TK libraries are
> compiled with this "multithreading" option.


I copied all the LIB files for Tcl and Tk to my project
directory and chose tcl84tsx.lib and tk84tsx.lib for
my project. This means "threads,static,msvcrt", right?

For my own project i compile with (C files):
/nologo /O2 /MT /Wi /D "WIN32" /D "NDEBUG" /D "STATIC_BUILD" \
/D "_WINDOWS" /D "_MBCS"

For linking it all together i choose my object files plus:
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib \
advapi32.lib shell32.lib oleaut32.lib uuid.lib odbc32.lib \
odbccp32.lib tcl84tsx.lib tk84tsx.lib msvcrt.lib /NODEFAULT

The parameters for compiling and linking are copied from an
example project that i once made. This example was not related
to Tcl/Tk, so they may be not really correct.

When linking i get errors for unresolved symbols like (not all):
__imp__stricmp
__imp__strnicmp
__imp__getpid
__imp__putenv
__imp__tzset
_isatty
__imp__ftime
__imp__InitCommonControlsEx@4
_ImmReleaseContext@8


Can anybody tell me what the correct parameters for compiling/
linking are?


Thanks for hints,
Torsten.

David Gravereaux

unread,
Dec 29, 2003, 11:10:38 PM12/29/03
to
Torsten Mohr <tm...@s.netic.de> wrote:

>Hi,
>
>thank you all for your very helpful hints. I now have
>several LIBs on my system available. But i still have
>some questions. These surely come up because i'm not
>experienced in Windows programming, but it would be great
>if somebody could give me some hints on these.
>
>>> To add threading do:
>>>
>>> nmake.exe -f makefile.vc OPTS=static,threads
>>>
>> You should also make sure that any modules of your own creation are
>> compiled with the -MT option since the static TCL and TK libraries are
>> compiled with this "multithreading" option.
>
>
>I copied all the LIB files for Tcl and Tk to my project
>directory and chose tcl84tsx.lib and tk84tsx.lib for
>my project. This means "threads,static,msvcrt", right?

yup.

>For my own project i compile with (C files):
>/nologo /O2 /MT /Wi /D "WIN32" /D "NDEBUG" /D "STATIC_BUILD" \
>/D "_WINDOWS" /D "_MBCS"

Oh, drop msvcrt in the options and rebuild. Tcl got compiled for -MD, so
they won't match. Or swap your project to -MD by choosing
project->settings->C/C++->Code Generation->Use RT library: Multithreaded
DLL

With -MT on your project your exe size will be about 300K larger, but won't
have a dep on msvcrt.dll. I find it not to bad to require msvcrt.dll.
It's not exactly part of the OS (but may be nowadays), but it's so common.
Or you may stay with libcmt (-MT), either way..

>For linking it all together i choose my object files plus:
>kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib \
>advapi32.lib shell32.lib oleaut32.lib uuid.lib odbc32.lib \
>odbccp32.lib tcl84tsx.lib tk84tsx.lib msvcrt.lib /NODEFAULT

Try not to use /NODEFAULTLIB if you can, it masks build errors.

>The parameters for compiling and linking are copied from an
>example project that i once made. This example was not related
>to Tcl/Tk, so they may be not really correct.
>
>When linking i get errors for unresolved symbols like (not all):
>__imp__stricmp
>__imp__strnicmp
>__imp__getpid
>__imp__putenv
>__imp__tzset
>_isatty
>__imp__ftime
>__imp__InitCommonControlsEx@4
>_ImmReleaseContext@8

yup, drop msvcrt from the options and rebuild tcl and tk.

David Gravereaux

unread,
Dec 30, 2003, 12:35:13 AM12/30/03
to
Torsten Mohr <tm...@s.netic.de> wrote:

>For linking it all together i choose my object files plus:
>kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib \
>advapi32.lib shell32.lib oleaut32.lib uuid.lib odbc32.lib \
>odbccp32.lib tcl84tsx.lib tk84tsx.lib msvcrt.lib /NODEFAULT

Add: comctl32.lib Imm32.lib tk_base.res (see below)
Subtract: msvcrt.lib (it's addition is automatic on the -M* switch)

>The parameters for compiling and linking are copied from an
>example project that i once made. This example was not related
>to Tcl/Tk, so they may be not really correct.
>
>When linking i get errors for unresolved symbols like (not all):
>__imp__stricmp
>__imp__strnicmp
>__imp__getpid
>__imp__putenv
>__imp__tzset
>_isatty
>__imp__ftime
>__imp__InitCommonControlsEx@4
>_ImmReleaseContext@8


To link with Tk, you'll need tk_src/win/rc/tk_base.rc along with the
contents it needs in tk_src/win/rc.

$(TMP_DIR)\tk_base.rc: \
$(RCDIR)\buttons.bmp \
$(RCDIR)\cursor*.cur

$(TMP_DIR)\tk_base.res : $(RCDIR)\tk_base.rc
$(RC) -fo $@ -r -i "$(GENERICDIR)" $(TCL_INCLUDES)
$(RCDIR)\tk_base.rc


Make me wonder if I should have makefile.vc do it for us by converting the
.res to an .obj and just inserting it in the static library for us.. hmmm

I'll look into it. Would be easiest.

David Gravereaux

unread,
Dec 30, 2003, 1:19:34 AM12/30/03
to
David Gravereaux <davy...@pobox.com> wrote:

>To link with Tk, you'll need tk_src/win/rc/tk_base.rc along with the
>contents it needs in tk_src/win/rc.
>
>$(TMP_DIR)\tk_base.rc: \
> $(RCDIR)\buttons.bmp \
> $(RCDIR)\cursor*.cur
>
>$(TMP_DIR)\tk_base.res : $(RCDIR)\tk_base.rc
> $(RC) -fo $@ -r -i "$(GENERICDIR)" $(TCL_INCLUDES)
>$(RCDIR)\tk_base.rc

Ignore that.. Just have your own .rc #include tk_base.rc is all that's
needed.

Torsten Mohr

unread,
Dec 30, 2003, 8:29:07 AM12/30/03
to
Hi,

> Add: comctl32.lib Imm32.lib tk_base.res (see below)
> Subtract: msvcrt.lib (it's addition is automatic on the -M* switch)

[...]


> To link with Tk, you'll need tk_src/win/rc/tk_base.rc along with the
> contents it needs in tk_src/win/rc.
>
> $(TMP_DIR)\tk_base.rc: \
> $(RCDIR)\buttons.bmp \
> $(RCDIR)\cursor*.cur
>
> $(TMP_DIR)\tk_base.res : $(RCDIR)\tk_base.rc
> $(RC) -fo $@ -r -i "$(GENERICDIR)" $(TCL_INCLUDES)
> $(RCDIR)\tk_base.rc

thanks for those hints (and the one with -MD). I changed the
whole project and put it on my web page for everybody who
may be interested.

http://www.s.netic.de/tmohr/c3.zip (2809 Bytes).

The Makefile is written for GNU make, which i know much better
than nmake. It may work with nmake, but i doubt that.

The project needs access to the compiled Tcl and Tk
sources (at least parts of it). This can be configured
with the first three lines in the Makefile.
For me the directory structure is:
|home
|---tcl
|----c3
| |-out
|----tcl
| |--generic
| |--win
| |--Released
|----tk
| |-generic
| |-win
| |--Released
| |--rc

It compiles fine on Windows and also starts the internal
exmple script.

But sadly, the script does not react to any input, so something
still is wrong. But it may be a nice starting point for any
other projects.


Thanks for all the hints, but (again), any hints to make it work
would be appreciated.


Kind regards,
Torsten.


0 new messages