Skip to content

build c executable with go static library, can not find header and .a #7

@helinwang

Description

@helinwang

I have a library client in folder ./client, and have an executable I want to build in folder ./client/test. But when doing make, it reports can not find header file (the header file is generated when doing go build).

./CMakeLists.txt:

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

cmake_minimum_required(VERSION 3.0)

project(cxx_go C Go)

include(cmake/golang.cmake)
include(cmake/flags.cmake)


add_subdirectory(client)
add_subdirectory(client/test)

./client/CMakeLists.txt:

ExternalGoProject_Add(pserver github.com/PaddlePaddle/Paddle/paddle/go/pserver)
add_go_library(client STATIC pserver)

./client/test/CMakeList.txt:

#include_directories(/home/helin/env/gopath/src/github.com/PaddlePaddle/Paddle/paddle/go/pserver/lib/build/client)
add_executable(main main.c)
add_dependencies(main client)
set (CMAKE_EXE_LINKER_FLAGS "-pthread")
#target_link_libraries(main /home/helin/env/gopath/src/github.com/PaddlePaddle/Paddle/paddle/go/pserver/lib/build/client/libclient.a)
target_link_libraries(main)

If I un-comment the two lines in above file, it could work. But how can I not hard code absolute path into the cmake file?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions