zildjohn01
Programmer
static library reference resolving
hi, i have two projects ( a static library and a exe ) that i am trying to interface with each other. the
static lib contains the entry point, calls a function in the exe, then the exe must have access back to the
static lib's functions. here is the code (in two projects):
Project StaticLib
Project Client
[maroon]A reference was added to project StaticLib[/maroon]
Partial output from the build: (wrapped for readability):
wow, i never thought i'd make a post that long
hi, i have two projects ( a static library and a exe ) that i am trying to interface with each other. the
static lib contains the entry point, calls a function in the exe, then the exe must have access back to the
static lib's functions. here is the code (in two projects):
Project StaticLib
Code:
// [highlight]stdafx.h[/highlight]
[ignore]#include <iostream>
#include <tchar.h>
#include <windows.h>[/ignore]
#define EXPOSED __declspec(dllexport)
// [highlight]testclass.h[/highlight]
namespace test {
class EXPOSED TestClass {
public:
static void DoSomething(int val);
};
}
// [highlight]testclass.cpp[/highlight]
#include "stdafx.h"
#include "TestClass.h"
namespace test {
void TestClass::DoSomething(int val) {
std::cout << "in func, val == " << val << "\n";
}
}
// [highlight]entrypoint.cpp[/highlight]
#include "stdafx.h"
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
int TestMain(HINSTANCE hInstance);
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
return TestMain(hInstance);
}
// [highlight]include.h[/highlight]
#include "stdafx.h"
#undef EXPOSED
#define EXPOSED __declspec(dllimport)
// now exposed means import, and the declarations can be reused
// to import to another project
#include "TestClass.h"
Project Client
[maroon]A reference was added to project StaticLib[/maroon]
Code:
// [highlight]main.cpp[/highlight]
#include "..\StaticLib\include.h"
int TestMain(HINSTANCE hInstance) {
test::TestClass::DoSomething(42);
return 50;
}
Partial output from the build: (wrapped for readability):
Code:
------ Build started: Project: Client, Configuration: Debug Win32 ------
Compiling...
main.cpp
Linking...
main.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) public: static void __cdecl test::TestClass::DoSomething(int)"
(__imp_?DoSomething@TestClass@test@@SAXH@Z)
referenced in function "int __cdecl TestMain(struct HINSTANCE__ *)"
(?TestMain@@YAHPAUHINSTANCE__@@@Z)
Debug/Client.exe : fatal error LNK1120: 1 unresolved externals
wow, i never thought i'd make a post that long