google / google/prefab

[BUG] prefab should set LINKER_LANGUAGE property for static libraries

Open
#161 3 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Kotlin
Stars
236
Forks
33
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
When a static library uses a C++ STL, the linker language of a library should be set to `CXX`.

**To Reproduce**
Steps to reproduce the behavior:
1. Package a C++ static library using prefab (let's name it `staticmodule::staticlib`). Make sure this library uses symbols from the STL. e.g. `std::string`, ...
2. Use the prefab module from step 1 in a C project:
```cmake
cmake_minimum_required(VERSION 3.0)
project(mygame)
find_package(staticmodule REQUIRED CONFIG)
add_library(mygame SHARED mygame.c)
target_link_libraries(mygame PRIVATE staticmodule::staticlib)
```
4. Building the `mygame` library will fail because the C linker will not find the c++ STL symbols.

**Expected behavior**
Linking just works.

**Additional context**
Prefab should add a [`LINKER_LANGUAGE`](https://cmake.org/cmake/help/latest/prop_tgt/LINKER_LANGUAGE.html) property:
e.g.
```
add_library(SDL2::SDL2-static STATIC IMPORTED)
set_target_properties(SDL2::SDL2-static PROPERTIES
IMPORTED_LOCATION "/home/maarten/.gradle/caches/transforms-3/3d84dffbc80dce10e99f69ce2cefa8de/transformed/SDL2-2.25.0/prefab/modules/SDL2-static/libs/android.arm64-v8a/libSDL2.a"
INTERFACE_INCLUDE_DIRECTORIES "/home/maarten/.gradle/caches/transforms-3/3d84dffbc80dce10e99f69ce2cefa8de/transformed/SDL2-2.25.0/prefab/modules/SDL2-static/include"
INTERFACE_LINK_LIBRARIES "-ldl;-lGLESv1_CM;-lGLESv2;-llog;-landroid;-lOpenSLES"
LINKER_LANGUAGE CXX # This line is currently missing
)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.