저는 총 3 개의 프로젝트로 내 문제를 설명하기 위해 두 가지 솔루션을 설정했습니다. 디버그 모드에서 컴파일하지만 릴리스 모드로 컴파일해도 문제가 계속 발생합니다.Visual Studio LNK1104 최소 예 :
MyRunnerCore.lib
은 3rdParty.lib
이 필요합니다. 왜 그런가? 내가 그걸 어떻게 할 수 있니?
아이디어는 내가 lib 디렉토리 프로젝트 (잘 작동)로 타사를 구축한다는 것입니다 : 여기
은 폴더를 구성하는 방법을 설명하는 그림이다. 그런 다음 cpp 파일의 lib 파일을 사용하여 MyRunnerCore를 빌드합니다 (올바르게 작동합니다). 마지막으로는 아니지만 MyRunnerCore.lib (LNK1104)를 사용하는 콘솔 응용 프로그램을 빌드합니다. 출력 창은 다음과 같이 표시됩니다.1>------ Build started: Project: MyRunnerCore, Configuration: Release Win32 ------
1> Core.cpp
1> MyRunnerCore.vcxproj -> C:\SO\MyRunner\Release\MyRunnerCore.lib
2>------ Build started: Project: MyRunner, Configuration: Release Win32 ------
2> main.cpp
2>LINK : fatal error LNK1104: cannot open file '3rdParty.lib'
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
다음은 Project가 어떤 설정을 편집 한 것을 가리키는 주석이있는 소스 파일입니다.
ThirdPartyClass.cpp
#include "ThirdParyClass.hpp"
int ThirdParyClass::GenerateNumber()
{ return 4; }
ThirdPartyClass.hpp
#pragma once
class ThirdParyClass
{ public: int GenerateNumber(); };
MAIN.CPP
//MyRunner Properties:
//Project Dependencies Added MyRunnerCore
//Include Directories Added $(SolutionDir)
//Library Directories Added $(OutDir)
#include <MyRunnerCore\Core.h>
#pragma comment (lib, "MyRunnerCore.lib")
int main() { Core c{}; return c.Run(); }
Core.cpp
#include "Core.h"
//MyRunnerCore Properties:
//Added To Include Path C:\SO\3rdParty
//Added To Library Path C:\SO\3rdParty\Debug
#include <3rdParty\ThirdParyClass.hpp>
#pragma comment(lib, "3rdParty.lib")
int Core::Run()
{
ThirdParyClass tp{};
return tp.GenerateNumber();
}
,174,
#pragma once
class Core
{ public: int Run(); };
Core.h 왜 링커는 링크 3rdParty.lib을 필요로 하는가?
링커 빌드를 만들기위한 설정이 누락 되었습니까? MyRunnerCore.lib
3rdParty.lib
을 참조하지 않고 빌드 하시겠습니까?
MSVC는 정적 라이브러리를 결합한 기능을 지원하지 않습니다. 명시 적으로 타사 라이브러리에 링크해야하며 라이브러리를 찾기 위해 링커에 설정된 경로에 있어야합니다. – drescherjm