NO

Author Topic: how to build a program with no link  (Read 2489 times)

whatsup

  • Guest
how to build a program with no link
« on: December 03, 2009, 07:35:23 PM »
first, I'm not new to Program in C, and I'm not new to Program for Windows,
but
I'm very new to Program in C for Windows.

what I'm trying to do is to build a program that doesn't depend on any lib except mine or the OS.

so I tried these:
in the compiler, I set target to console, and dll library.
in the linker, I deleted libs references.

in a test.c I wrote this code:

Code: [Select]
void PostQuitMessage (long nExitCode);
int main(void)
{
PostQuitMessage(0);
return 0;
}

I got a link error
then I tried to set the linker's libs to "C:\Windows|System32\kernel32.dll"
didn't work.
I tried some more, but didn't work.

note: I did manage to make a working program, when i used default settings.

can someone please show me the steps, what settings, code, etc...
I need to make for the above code to work with out any lib except Windows's ?

skirby

  • Guest
Re: how to build a program with no link
« Reply #1 on: December 04, 2009, 02:47:05 PM »
Hello whatsup,

I am not sure to understand. What do you want to do exactly?
Why don't you want to link your code with standard windows dll?

Kernel32.dll, user32.dll are present on all windows. So you can have a link to these dll.

More, if you want to use (like in your example) the function PostQuitMessage, you have to link your code to user32.lib otherwise the compiler cannot find the reference.

whatsup

  • Guest
Re: how to build a program with no link
« Reply #2 on: December 05, 2009, 06:03:53 PM »
Quote
what I'm trying to do is to build a program that doesn't depend on any lib except mine or the OS.

thank for reply.
that's what I asked, I want to link only the OS lib that I use, not any other lib/ PellesC kernel lib.


Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: how to build a program with no link
« Reply #3 on: December 06, 2009, 09:48:53 AM »
Study this code:
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
void __cdecl WinMainCRTStartup(void)
{
MessageBox(0, "Hello World!", "WinTest", MB_OK);
ExitProcess(0);
}
May the source be with you