bazel-contrib / bazel-contrib/rules_foreign_cc
Linker flags not getting applied
- Dominant language
- Starlark
- Stars
- 737
- Forks
- 270
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to build a module from the Juce library. It builds successfully on the command line using the following
```
cmake . -B cmake-build -DJUCE_BUILD_EXAMPLES=ON -DJUCE_BUILD_EXTRAS=ON
cmake --build cmake-build --target AudioPluginHost
```
This also builds correctly (but fails because the output is a folder.
```
genrule(
name = "PluginHostGen",
outs = ["AudioPluginHost"],
srcs = [":all_srcs"],
cmd = """ \
cmake ThirdParty/Juce/JUCE -B cmake-build -DJUCE_BUILD_EXAMPLES=ON -DJUCE_BUILD_EXTRAS=ON
cmake --build cmake-build --target AudioPluginHost
""",
)
```
However, this fails:
```
cmake (
name = "PluginHost",
cache_entries = {
"JUCE_BUILD_EXAMPLES":"ON",
"JUCE_BUILD_EXTRAS":"ON",
},
linkopts = [
"-lm",
"-ldl",
"-lpthread",
],
lib_source = ":all_srcs",
working_directory = "JUCE",
targets = ["AudioPluginHost"],
out_binaries = ["PluginHost"],
)
```
Producing this error:
```
/usr/bin/ld:
CMakeFiles/juceaide.dir/__/__/__/modules/juce_gui_basics/juce_gui_basics.cpp.o:
undefined reference to symbol 'exp@@GLIBC_2.29'
/usr/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO
missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [extras/Build/juceaide/CMakeFiles/juceaide.dir/build.make:194:
extras/Build/juceaide/juceaide_artefacts/Debug/juceaide] Error 1
make[1]: *** [CMakeFiles/Makefile2:131:
extras/Build/juceaide/CMakeFiles/juceaide.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
```
To reproduce this, you can pull the JUCE git repo and try executing any of these from the root folder, I'm using the 7.0.7 release of Juce. I'm also using rules_foreign_cc 0.9.0 and cmake 3.22.1 on Ubuntu 22.04
https://github.com/juce-framework/JUCE
Contributor guide
Research direction
Start by reproducing the JUCE 7.0.7 build with rules_foreign_cc 0.9.0, CMake 3.22.1, and the shown cmake rule, comparing it with the genrule command. Read the cmake rule's handling of linkopts and the generated linker command. Done means the PluginHost target applies the listed linker flags and builds successfully on Ubuntu 22.04.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100