Skip to content

Commit 1979e58

Browse files
RahulHereRahulHere
authored andcommitted
Fix C API linking when only shared libraries are built
The C API was incorrectly checking for a non-existent gopher-mcp-shared target, causing it to try linking against static libraries that don't exist when BUILD_STATIC_LIBS=OFF. Changes: - Check BUILD_SHARED_LIBS variable instead of non-existent target - Prefer shared libraries when available - Fall back to static only when shared libs not built
1 parent ef8c465 commit 1979e58

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/c_api/CMakeLists.txt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,27 @@ target_include_directories(gopher_mcp_c
140140
${CMAKE_BINARY_DIR}/_deps/fmt-src/include
141141
)
142142

143-
# Link with shared libraries
143+
# Link with shared libraries
144144
# The shared library already contains all needed dependencies
145-
# When gopher-mcp is built as static only, link to static version
146-
if(TARGET gopher-mcp AND NOT TARGET gopher-mcp-shared)
147-
# gopher-mcp exists but no shared version - it's an alias to static
145+
# Prefer shared libraries when available, fall back to static
146+
if(BUILD_SHARED_LIBS AND TARGET gopher-mcp)
147+
# Shared libraries are being built - use them
148+
target_link_libraries(gopher_mcp_c
149+
PRIVATE
150+
gopher-mcp
151+
gopher-mcp-event
152+
gopher-mcp-logging
153+
)
154+
elseif(TARGET gopher-mcp-static)
155+
# Only static libraries available
148156
target_link_libraries(gopher_mcp_c
149157
PRIVATE
150158
gopher-mcp-static
151159
gopher-mcp-event-static
152160
gopher-mcp-logging-static
153161
)
154162
else()
155-
# Normal case - shared libraries exist
156-
target_link_libraries(gopher_mcp_c
157-
PRIVATE
158-
gopher-mcp
159-
gopher-mcp-event
160-
gopher-mcp-logging
161-
)
163+
message(FATAL_ERROR "No gopher-mcp library target found")
162164
endif()
163165

164166
# Add nghttp2 linking if needed

0 commit comments

Comments
 (0)