Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ LNK2001 after linking libprotobuf.lib #12940

Closed
DuKeM-CSGO opened this issue May 31, 2023 · 2 comments
Closed

C++ LNK2001 after linking libprotobuf.lib #12940

DuKeM-CSGO opened this issue May 31, 2023 · 2 comments
Assignees
Labels
c++ inactive Denotes the issue/PR has not seen activity in the last 90 days.

Comments

@DuKeM-CSGO
Copy link

Seems like a dup of #12693, #12637, #12292.
I use ADD_SUBDIRECTORY("src/deps/protobuf") in the root and the following is the CMakeLists.txt in the sub dir:

CMAKE_MINIMUM_REQUIRED(VERSION 3.26)

FETCHCONTENT_DECLARE(
	protobuf
	GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
	GIT_TAG v23.2
)

FETCHCONTENT_GETPROPERTIES(protobuf)
IF(NOT protobuf_POPULATED)
	FETCHCONTENT_POPULATE(protobuf)
ENDIF()

SET(PROTOBUF_BINARY_LIB
	"${protobuf_BINARY_DIR}/install/lib/libprotobuf$<$<CONFIG:Debug>:d>.lib"
)

SET(PROTOBUF_BINARY_PROTOC
	"${protobuf_BINARY_DIR}/install/bin/protoc.exe"
	PARENT_SCOPE
)

SET(protobuf_BINARY_DIR ${protobuf_BINARY_DIR} PARENT_SCOPE)
SET(protobuf_SOURCE_DIR ${protobuf_SOURCE_DIR} PARENT_SCOPE)

ADD_CUSTOM_COMMAND(
	OUTPUT ${PROTOBUF_BINARY_LIB} ${PROTOBUF_BINARY_PROTOC}
	DEPENDS ${protobuf_SOURCE_DIR}
	WORKING_DIRECTORY ${protobuf_BINARY_DIR}
	COMMAND ${CMAKE_COMMAND} "-DCMAKE_INSTALL_PREFIX=./install" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_ABSL_PROVIDER="module" -G "${CMAKE_GENERATOR}" -T "${CMAKE_GENERATOR_TOOLSET}" -A "${CMAKE_GENERATOR_PLATFORM}" "${protobuf_SOURCE_DIR}"
	COMMAND ${CMAKE_COMMAND} --build . --config Release --target install -v -- -r
	COMMENT "Building protoc"
)

ADD_CUSTOM_TARGET(
	protobuf_build
	DEPENDS protobuf
	SOURCES ${PROTOBUF_BINARY_LIB} ${PROTOBUF_BINARY_PROTOC}
)

ADD_DEPENDENCIES(
	${PROJECT_NAME}
	protobuf_build
)

TARGET_LINK_LIBRARIES(
	${PROJECT_NAME}
	PRIVATE "${PROTOBUF_BINARY_LIB}"
)

TARGET_INCLUDE_DIRECTORIES(
	${PROJECT_NAME}
	PRIVATE "${protobuf_BINARY_DIR}/install/include"
)

Then I see libprotobuf.lib is built successfully, but it can't build the main.exe which includes libprotobuf.lib and pb.ccs:

libprotobuf.lib(common.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]
libprotobuf.lib(text_format.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]
libprotobuf.lib(descriptor_database.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]
libprotobuf.lib(dynamic_message.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]
libprotobuf.lib(tokenizer.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]
libprotobuf.lib(zero_copy_stream_impl_lite.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]
libprotobuf.lib(zero_copy_stream_impl.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]
libprotobuf.lib(implicit_weak_message.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]
libprotobuf.lib(extension_set_heavy.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]
libprotobuf.lib(generated_message_tctable_lite.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]
libprotobuf.lib(reflection_ops.obj) : error LNK2001: unresolved external symbol "private: void __cdecl absl::lts_20230125::log_internal::LogMessage::CopyToEncodedBuffer(class std::basic_string_view<char,struct std::char_traits<char> >,enum absl::lts_20230125::log_internal::LogMessage::StringType)" (?CopyToEncodedBuffer@LogMessage@log_internal@lts_20230125@absl@@AEAAXV?$basic_string_view@DU?$char_traits@D@std@@@std@@W4StringType@1234@@Z) [F:\Github\RoadtoCmake\build\Release\RoadtoCmake.vcxproj]

Anything I can do? I only want to use cmake to build the project, no manually git clone or installing an external abseil. Neither including absl in my own CMakelists.txt.

@DuKeM-CSGO DuKeM-CSGO added the untriaged auto added to all issues by default when created. label May 31, 2023
@anandolee anandolee added c++ and removed untriaged auto added to all issues by default when created. labels Jun 1, 2023
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Nov 11, 2023
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ inactive Denotes the issue/PR has not seen activity in the last 90 days.
Projects
None yet
Development

No branches or pull requests

3 participants