Skip to content

[BUG] C executable linking to C++ shared library #1183

@huangqinjin

Description

@huangqinjin

Environment Details

  • NDK Version: any
  • Build system: CMake
  • Host OS: Linux
  • ABI: arm64-v8a
  • NDK API level: any

Description

f.cpp:

#include <iostream>
extern "C" int f()
{
    std::cout << "hello" << std::endl;
}

main.c:

int f();
int main()
{
    f();
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.6)
project(Test)

add_library(f SHARED f.cpp)
add_executable(Test main.c)
target_link_libraries(Test f)
cmake .. -DCMAKE_TOOLCHAIN_FILE=${NDK}/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_STL=c++_shared && cmake --build .

warning: libc++_shared.so, needed by libf.so, not found (try using -rpath or -rpath-link)
libf.so: undefined reference to `vtable for std::length_error'
libf.so: undefined reference to `__cxa_throw'
...

No error for ABIs: armeabi-v7a, x86, x86_64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions