Thanks, CommonTater.
Now, I've got another noob question. How come when I do:
#include <stdio.h>
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
... I don't have to point the program anywhere else, and it seems to know what to do to find the relevant libraries,
Those are not libraries they're "headers" or Include Files... It finds them because their folders are listed in
Tools -> Options -> Folders -> Include
whereas, when I do this:
#include <myown.h>
That should be
#include "myown.h" since the file is in your project folder...
"" is for local include files, in the same folder as your source code
<> is for include files on the search path (as above)
My program gets broken, even though I've added the folder my .lib file is in into the project options. My program only works when I do this:
#pragma lib "myown.lib"
Is this how it's done, or is there another "professional, non noob" way of doing this?
Thanks all!
You should use the $pragma lib
only when including libraries (*.lib).
Usually when writing a C program with multiple source files one is not making libraries. C Source files compile to objects, not libraries, in the project\output folder and the linker knows to find them there. The include (header) files are used to alert the compiler to a function or variable in a different source file.
For example...
// main.c
#include <stdio.h> // header on search path
#include "domath.h" // header in local directory
int main (void)
{ int x = 21;
int y = 0;
printf(" x = %d\t y = %d\n", x, y);
// call function in different source file
y = timestwo(x);
printf(" x = %d\t y = %d\n", x, y);
return 0; }
// domath.h
#ifndef DOMATH_H // include guard
#define DOMATH_H // prevents multiple inclusions
int timestwo(int var); // function prototype
#endif // include guard
// domath.c
int timestwo(int var)
{ return var * 2; }
While this is an extremely trivial example, it should give you the general idea about how these things are set up.
Hope this helps.