ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • warning LNK4042
    Study/C&C++ 2016. 8. 30. 10:43

    프로젝트 빌드시, 링크 과정에서 warning LNK4042와 함께 error가 발생한다.

    warning LNK4042: 개체가 두 번 이상 지정되었습니다. 나머지는 무시됩니다.

    warning LNK4042: object specified more than once; extras ignored.

    이 경우, 아무리 찾아도 코드나 프로젝트 설정에서 오류를 찾을 수가 없다.

    검색해 보면, 빌드 히스토리를 지우거나, object file 이름을 바꾸거나, namespace를 바꾸는 등의 방법이 나오지만,

    근본적인 해결 방법은 아니었다.


    가장 신빙성있는 원인은 아래 링크에서 발견하였다.


    http://stackoverflow.com/questions/3695174/visual-studio-2010s-strange-warning-lnk4042


    I had a similar problem with linker warning LNK4042: object specified more than once; extras ignored. In my case Visual Studio was trying to compile both header and source files with the same name - MyClass.h and MyClass.cpp. It happened because I renamed .cpp file to .h and Visual Studio got confused. I noticed the problem by looking at the compiler logs in the Debug directory. To resolve just remove .h file from the project then add it again.


    project 파일에서 Class.cpp 파일과 Class.h 파일이 둘 다 source 파일로 설정되었긴 때문이라는 내용이었다.

    Project.vcxproj 파일을 열어서 보니 정말 그렇다.


    잘못된 경우

    <ClCompile Include="Class.cpp" />

    <ClCompile Include="Class.h" />


    바르게 수정된 경우

    <ClCompile Include="Class.cpp" />

    <ClInclude Include="Class.h" />


    source file은 ClCompile, header file은 ClInclude로 포함되어야 한다.


    'Study > C&C++' 카테고리의 다른 글

    Resource view 에러  (0) 2016.08.07
    Timer Resolution 향상: 15.6ms -> 1ms  (0) 2016.01.07
    Chrono  (0) 2015.11.20
    [펌] [VS2010] _AFXDLL 버그 리포트  (0) 2013.01.21
    [VS2010] 인텔리센스 에러: /MD _AFXDLL  (0) 2012.05.04
Designed by Tistory.