G
GaryMeer
Guest
I am getting a LNK2001 error when I try to use external variables as global variables in my program,. I have used these for decades in C on Unix. Now Visual Studio is getting LNK2001 errors from the linker when trying to link a C++ program I am developing. On every other system I have used the 1st module to refer to the external allocates space for it. Is Microsoft different? The code runs along the lines of:
----------------------------------------------------------------
header.h
#include <cstdio>
extern char programName[ FILENAME_MAX ];
void subr();
void subr2();
----------------------------------------------------------------
main.cpp
#include "header.h"
int main(argc, char **argv)
{
programName = argv[0];
subr();
subr2();
}
----------------------------------------------------------------
subr.cpp
#include "header.h"
void subr()
{
}
----------------------------------------------------------------
subr2.cpp
#include "header.h"
void subr2()
{
}
All of the routines compile cleanly, but then the linker error. Any ideas?
Continue reading...
----------------------------------------------------------------
header.h
#include <cstdio>
extern char programName[ FILENAME_MAX ];
void subr();
void subr2();
----------------------------------------------------------------
main.cpp
#include "header.h"
int main(argc, char **argv)
{
programName = argv[0];
subr();
subr2();
}
----------------------------------------------------------------
subr.cpp
#include "header.h"
void subr()
{
}
----------------------------------------------------------------
subr2.cpp
#include "header.h"
void subr2()
{
}
All of the routines compile cleanly, but then the linker error. Any ideas?
Continue reading...