Author Topic: gcc links automatically? but cl.exe does not (windows)  (Read 8099 times)

Offline soren

  • Jr. Member
  • *
  • Posts: 6
gcc links automatically? but cl.exe does not (windows)
« on: August 22, 2011, 12:11:58 PM »
hi, (total noob). I cant work out why when I assemble helloworld.asm (using nasm -f win32 helloworld.asm) i can then convert the object file to an exe with  simple "gcc helloworld.obj", but if i use microsofts cl.exe  i get:

helloworldasm.obj : error LNK2001: unresolved external symbol _printf
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
helloworldasm.exe : fatal error LNK1120: 2 unresolved externals


in microsfts tool i have to use the linker:
link helloworld.obj libcmt.lib

why is gcc able to act as a linker while cl.exe does not?

Offline Dumah

  • Jr. Member
  • *
  • Posts: 4
Re: gcc links automatically? but cl.exe does not (windows)
« Reply #1 on: August 22, 2011, 07:14:27 PM »
AFAIK, gcc just calls the 'ld' command to do the business.

With regard to using the lib, I think gcc just assumes everything uses libc so chucks it in. VC++ doesnt

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: gcc links automatically? but cl.exe does not (windows)
« Reply #2 on: August 22, 2011, 08:32:45 PM »
That sounds right. With Linux, anyway, gcc calls ld with a "correct" command line - including libc. If I call ld directly, I have to put "-lc" on the command line (if I'm using libc).

It was a long, long time ago that I last used an MS compiler. As I recall, I called cc.exe, and it called cl.exe (and other things?). If you've got a "cc.exe", it might be worth a try...

Best,
Frank


Offline soren

  • Jr. Member
  • *
  • Posts: 6
Re: gcc links automatically? but cl.exe does not (windows)
« Reply #3 on: August 23, 2011, 02:27:36 AM »
ahh ok. i wish ever class of tool (linker, compiler)  worked the same so as i didnt have to remember the different defaults and behavious.   >:(  ;D