I have created a sample c++ project under Visual Studio 2010 with following files.
A.h
#ifndef A_H
#define A_H
#include <iostream>
void foo();
#endif
A.cpp
#include "A.h"
void foo()
{
int a = 1;
}
main.cpp
#include "A.h"
int main(int argc, char* argv[])
{
foo();
return 0;
}
I am getting the following output after build:
1>------ Build started: Project: opengl_test, Configuration: Debug Win32 ------
1> main.cpp
1> A.h
1> A.cpp
1> Generating Code...
1>Debug\A.obj : warning LNK4042: object specified more than once; extras ignored
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl foo(void)" (?foo@@YAXXZ) referenced in function _main
1>C:\Users\alp\Projects\Test Samples\opengl_test\Debug\opengl_test.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
What is the reason for this error?
A.h
,A.cpp
, andmain.cpp
) and then compiled. Works fine, no errors. So the question is, what's different about your setup than mine (and what you've described in the question)? – Cody GrayA
that could be messing the linker up if/when it flattens the hierarchy? – Cody Gray