首页 > 解决方案 > 两个相同的项目:一个有未解决的外部问题,另一个没有

问题描述

我有两个 VS 2017 项目,它们在结构上是相同的。

他们两个:

#pragma once

#undef UNICODE

#define WIN32_LEAN_AND_MEAN

#include <iostream>
#include <map>
#include <random>
#include <cstdlib>
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>

#include "my_problem_library.pb.h"

// Need to link with Ws2_32.lib
#pragma comment( lib, "Ws2_32.lib" )

#define DEFAULT_BUFLEN 512
#define DEFAULT_PORT "6000"

在 project1 中,代码编译没有任何问题。它使用与 project2 完全相同的功能my_problem_library,但是当我编译 project2 时,我得到了这些错误:

error LNK2001: unresolved external symbol "public: virtual __cdecl GameInfo::GameInformation::~GameInformation(void)" (??1GameInformation@GameInfo@@UEAA@XZ)
error LNK2001: unresolved external symbol "protected: __cdecl GameInfo::GameInformation::GameInformation(class google::protobuf::Arena *)" (??0GameInformation@GameInfo@@IEAA@PEAVArena@protobuf@google@@@Z)
error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl google::protobuf::internal::LogFinisher::operator=(class google::protobuf::internal::LogMessage &)" (__imp_??4LogFinisher@internal@protobuf@google@@QEAAXAEAVLogMessage@123@@Z)
...
fatal error LNK1120: 13 unresolved externals

导致这些错误的函数都位于my_problem_library.pb.h(这是自动生成的,我可能会添加)。

我错过了另一个进口吗?为什么这适用于 project1 而不是 project2?

欢迎所有见解。

标签: c++visual-studio

解决方案


推荐阅读