-
Multiple .c files
Hi!
I'm working on some project and I want to write multiple .c files (each .c file for a dialog). Now I have main.c and about.c files and if I want to compile this I get these errors:
About.obj : error LNK2005: _szAppName already defined in main.obj
Release/Address Book.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
What is wrong and how to use multiple files?
I'm using Visual C++ 5.0 on Win98.
-
Looks like you have 2 instances of a global variable......this is fine when compiling 1 source file....but when you try link tham all...it leads to conflicts...
Look through your code for this error......and try limit the amount of globals that you use.......this will help minimise this problem
-
that is because you must separate the code for each module into pair of .c and .h file. Like this
Code:
////////////////////////////////////////
///MyDlg.h
//declaration file
struct MyDlg
{
HWND m_hWnd;
char title[255];
};
MyDlg gMyDlg;
void Create( void );
////end of h file
///////////////////////////////////////
//MyDlg.c
//definition file
#include"MyDlg.h"
void Create( void )
{
.....use gMyDlg....here
}
///end of c file
/////////////////////////////////////
//main
#include"MyDlg.h"
void main(void)
{
}
remember that you must not include .c files only .h files
-
Thanks Fordy. The global variables were the problem.