[英]Third party library throwing compilation errors when being included in project
I am trying to write a plugin for a program, and I am using protobuf for communication.我正在尝试为程序编写插件,并且正在使用 protobuf 进行通信。 I had to install the protobuf libraries from source, and this was done without any compilation errors.
我必须从源代码安装 protobuf 库,并且这样做没有任何编译错误。 However, after I link and include the appropriate libraries and headers, respectively, I get errors coming from the protobuf headers, like
may not be initialized
.但是,在我分别链接并包含适当的库和头文件后,我收到来自 protobuf 头文件的错误,例如
may not be initialized
。 It appears to be linking correctly as there are no undefined sources and including correctly for intellisense is finding the symbols in those files.它似乎正确链接,因为没有未定义的来源,并且正确包含智能感知是在这些文件中找到符号。 I have tried disabling the
treat warnings as errors
and the sdl
compiler flags, but these do not solve my problem.我曾尝试禁用
treat warnings as errors
和sdl
编译器标志,但这些并不能解决我的问题。 To clarify, the problem is:澄清一下,问题是:
static constexpr int kMessageSetMessageNumber = 3;
says that it may not be initialized
and说它
may not be initialized
并且
static const int kMessageSetItemStartTag = GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG(
kMessageSetItemNumber, WireFormatLite::WIRETYPE_START_GROUP);
which must be a constant expression
.这
must be a constant expression
。 And, again, when building from source in VS2015, these errors do not appear;而且,在 VS2015 中从源代码构建时,不会出现这些错误; they appear when I try using the protobuf lib and include directories that were just built and installed.
当我尝试使用 protobuf lib 并包含刚刚构建和安装的目录时,它们就会出现。 This lead me to thinking of the flags solution as stated above.
这让我想到了上述的标志解决方案。 In my top level CMakeLists, I have
在我的顶级 CMakeLists 中,我有
FIND_PACKAGE(Protobuf EXACT 3.13.0.0 REQUIRED PATHS "$ENV{ProgramW6432}/protobuf")
which gets the lib and include for protobuf successfully and in my subdirectoy, the CMakeLists is它成功获取lib并包含protobuf,并且在我的子目录中,CMakeLists是
project(ZMQReceiverV2)
add_library(${PROJECT_NAME} STATIC
./ZMQReceiverV2.cpp
./ZMQReceiverV2.h
)
target_link_libraries(${PROJECT_NAME}
...
${Protobuf_LIBRARY}
libprotobuf
libprotobuf-lite
libprotoc
)
target_include_directories(${PROJECT_NAME}
SYSTEM PUBLIC
...
PUBLIC ${protobuf_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
Though, I am thinking the issue is compiler configuration or of this nature, I included my cmakelists, incase you think the problem lies with that.不过,我认为问题是编译器配置或这种性质,我包括了我的 cmakelists,以防您认为问题出在那里。
Can you help me resolve this issue?你能帮我解决这个问题吗? Thanks in advance
提前致谢
Thanks to everyone for your answers.感谢大家的回答。 The issue was that I had two installs of the library, and only one was working.
问题是我安装了两个库,但只有一个在工作。 So after removing the messed up one and fixing my cmake variables, I was able to compile my plugin.
因此,在删除混乱的一个并修复我的 cmake 变量后,我能够编译我的插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.