적당한 정수를 global에 선언하고(상수로 쓸 목적) 헤더에 넣은 후 그 초기화 모듈과 헤더파일을
여러 프로젝트에서 참조하게 하려고 했는데 잘 안 되네요.
-----consts.h----------------
unsigned int CONST1;
------------------------------
-----init.h--------------------
void initConst();
-----------------------------
----init.cpp---------------
CONST1=RegisterWindowMessage(TEXT(\"메시지\")); // 적당한 숫자를 CONST1에 대입해 주는 Win32 API
---------------------------------------
=========================여기까지 Project1.lib로 컴파일 잘 됨============
==Project 2 [Executable]=====================
---exe.cpp---------------------------
#include \"../Project 1/init.h\"
#include \"../Project 1/consts.h\"
int func() {
int a = 3 * CONST1;
}
...
-------------------------------링크 안 됨 [CONST1 중복 선언: Project1.lib(init.obj)과 exe.obj]--------
그래서 exe.cpp를 다음과 같이 고쳤더니
----------------------------
#include \"../Project 1/init.h\"
extern \"C\" {
#include \"../Project 1/consts.h\"
}
.........
-----------------------
링크는 되지만 CONST1에 제대로 된 값이 들어가지 않음...
뉴비에게 자비를...
헤더 - extern int CONST1; 소스파일 어디엔가 - int CONST1;
음 그러니까 CONST1 선언을 Project1의 헤더에다 하지 말고 Project2에다 하라는 말씀인가요? 근데 그럼 헤더를 만드는 의미가 없는데;;
Project1의 init.cpp에다 consts.h의 선언을 전부 갖다 붙이고 extern 처리하니까 되는군요-_-;;