NO

Author Topic: Linking for Windows  (Read 5034 times)

sal55

  • Guest
Linking for Windows
« on: January 31, 2014, 11:06:18 PM »
I have this program:

#include <windows.h>

int main(void){
 MessageBoxA(0,"One","Two",0);
}

It's compiled like this:

C:\pellesc\bin\pocc.exe /IC:\pellesc\include /IC:\pellesc\include\win -Tamd64-coff -Ze /Ot program.c

producing program.obj, and linked like this:

C:\pellesc\bin\polink /LIBPATH:c:\pellesc\lib  /LIBPATH:c:\pellesc\lib\win64 /OUT:program.exe @filelist

where filelist contains one line with program.obj

However it gives the error:  POLINK: error: Unresolved external symbol '__imp_MessageBoxA'.

What do I have to do to link for Windows? This is for Pelles C 64-bits and runs on 64-bit Windows 7; does MessageBoxA still exist in this version?

Thanks.



Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2116
Re: Linking for Windows
« Reply #1 on: January 31, 2014, 11:33:02 PM »
MSDN gives that info in here.
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma comment(lib, "user32.lib")
int main(void){
return MessageBoxA(0,"One","Two",0);
}
May the source be with you

sal55

  • Guest
Re: Linking for Windows
« Reply #2 on: January 31, 2014, 11:56:39 PM »
MSDN gives that info in here.
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma comment(lib, "user32.lib")
int main(void){
return MessageBoxA(0,"One","Two",0);
}

Thanks, that worked. But, I have some questions about this:

o Why can't it just pick up the user32.lib file from the search path I've given it? (Actually why doesn't it just work? With other C compilers (gcc, lccwin, DMC) it doesn't need anything extra to link properly.)

o Will I need one of these for each library such as kernel32.lib etc? (I assume the pragmas are only needed in one module)

o Is there any #if expression I can use to detect that Pelles C is running? (In case I need to turn off the pragma when I want the same code to run on, say, lccwin, which doesn't like the syntax)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2116
Re: Linking for Windows
« Reply #3 on: February 01, 2014, 01:58:52 AM »
o Why can't it just pick up the user32.lib file from the search path I've given it? (Actually why doesn't it just work? With other C compilers (gcc, lccwin, DMC) it doesn't need anything extra to link properly.)
you can, insert it to filelist in own line
Quote
o Will I need one of these for each library such as kernel32.lib etc? (I assume the pragmas are only needed in one module)
only one of each and without pragmas too.
Quote
o Is there any #if expression I can use to detect that Pelles C is running? (In case I need to turn off the pragma when I want the same code to run on, say, lccwin, which doesn't like the syntax)
__POCC_ as help says ;)

BTW: have you checked povars32.bat from Pelles\bin ?
« Last Edit: February 01, 2014, 09:45:50 AM by timovjl »
May the source be with you

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Linking for Windows
« Reply #4 on: February 01, 2014, 10:29:24 AM »
o Why can't it just pick up the user32.lib file from the search path I've given it? (Actually why doesn't it just work? With other C compilers (gcc, lccwin, DMC) it doesn't need anything extra to link properly.)

Some of these compilers resolve dependencies on their own or have more libraries added by default.
---
Stefan

Proud member of the UltraDefrag Development Team

sal55

  • Guest
Re: Linking for Windows
« Reply #5 on: February 01, 2014, 12:23:39 PM »
you can, insert it to filelist in own line

OK, that worked, thanks. But I'm still puzzled why it couldn't find it in the LIB\WIN64 path I gave it.

Quote
__POCC_ as help says ;)
Yes, but I have to find it first! (And even armed with this information, I can't find any trace of it, not in help0009.chm)

Quote
BTW: have you checked povars32.bat from Pelles\bin ?
I've tried povars64.bat, but I prefer to do it without having to run this (I can't even remember how to auto-run a batch file!).

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2116
Re: Linking for Windows
« Reply #6 on: February 01, 2014, 01:33:09 PM »
Quote
__POCC_ as help says ;)
Yes, but I have to find it first! (And even armed with this information, I can't find any trace of it, not in help0009.chm)
Commanline tools -> POCC compiler -> Predefined preprocessor symbols  ;)

Quote
BTW: have you checked povars32.bat from Pelles\bin ?
I've tried povars64.bat, but I prefer to do it without having to run this (I can't even remember how to auto-run a batch file!).
Create shortcut with target %COMSPEC% /k c:\PellesC\bin\povars64.bat for console ;)
« Last Edit: February 01, 2014, 01:43:00 PM by timovjl »
May the source be with you

Persay

  • Guest
Re: Linking for Windows
« Reply #7 on: March 04, 2014, 10:13:04 AM »
^^ Thanks i missed that :)