Author Topic: static linking  (Read 5310 times)

phenex

  • Guest
static linking
« on: October 06, 2006, 04:22:55 pm »
hi folks,
can anyone explain how i can use the argument "-static" in codeblocks,
i try it since a couple of hours but nothing works.

thanks a lot! phen  8)

phenex

  • Guest
Re: static linking
« Reply #1 on: October 07, 2006, 11:27:20 am »
... i want to link the runtimes static.
i heard the gcc/mingw option for this is "-static", but i dont know how i can use this option in code::blocks.
"build > compiler options > linker > other linker options: -static" doesnt work :(

phen

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: static linking
« Reply #2 on: October 07, 2006, 12:41:40 pm »
It is difficult to answer when one does not understand the question.
Sarek, Star Trek: The Voyage Home

In other words, it may be helpful if you elaborate "nothing works" a bit more and give more detailled information about your system. A copy of your compiler's/linker's commandline and error messages might be helpful, too. Just "nothing works" is not an awful lot of information.

In general, the -static option does what you want in gcc/MinGW, on systems that do support it, and if the required libraries are found. It normally works without that flag, however, by selecting the correct library (a static one).
If you refer to one of glibc/glibc++/MinGW stub as "the runtime", this is always linked statically anyway.
If you refer to MSVCRT.DLL as "the runtime", then I am afraid this will not work, at least not without a lot of hacking and violating the law.
(EDIT: It's not necessary, anyway, since MSVCRT is/should be on every computer.)
« Last Edit: October 07, 2006, 12:44:21 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

phenex

  • Guest
Re: static linking
« Reply #3 on: October 07, 2006, 01:24:57 pm »
hi thomas thanks for the answer.
my problem is, when i make a program with c::b and give it to a friend then always comes this error:
This application has failed to start because the application configuration is incorrect.
i heard i can solve this problem by using '-static', but the size of my app doesnt change if i use it.
because of this i think it doesnt work.

but if i enable the whole commandline output i can see this:
Code
mingw32-g++.exe    -Os     -IC:\Programme\CodeBlocks\include -c main.cpp -o .objs\main.o
windres.exe -i icon.rc -J rc -o .objs\icon.res -O coff   
mingw32-g++.exe    -LC:\Programme\CodeBlocks\lib -o .\test\test.exe .objs\main.o  .objs\icon.res     -s -static

phen (please excuse my poor english)

phenex

  • Guest
Re: static linking
« Reply #4 on: October 08, 2006, 05:40:41 pm »
is it still to unexactly? :)
please guys give me a hint - its very important for me to solve that problem.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: static linking
« Reply #5 on: October 08, 2006, 07:45:31 pm »
The commandline that you posted shows no problem, it should work just fine.

Since you don't explicitely link to anything, I don't see how it could fail with this error. That is, except if your friend does not have MSVCRT.DLL (that's the only dependency your program implicitely has), but that is kind of unbelieveable.

MSVCRT.DLL is a standard component used by almost every Windows program, so it seems very unlikely that it is not present on a computer. Nevertheless, try to copy that DLL to the other computer (or download it from dll-files.com).
If I remember correctly, it is perfectly legal to distribute this DLL in unmodified form with your programs, too (you may want to verify this before doing it).

If copying MSVCRT.DLL does not help, there is one last thing you can do:
Go to www.sysinternals.com and download FileMon. Start it before launching your program. You should see several dozen events in FileMon's output window. At some place, it will read "SOME_LIBRARY.DLL   -- NOT FOUND". Then you will know what is missing.
Alternatively, you could use the dependency walker coming with Microsoft's developer tools, if you have these, but FileMon will do as well.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."