Uh oh!
There was an error while loading. Please reload this page.
Support relative path for CMAKE_INSTALL_*DIR - #1119
Merged
redboltz merged 1 commit intoApr 26, 2024
Merged
Conversation
redboltz
commented
Apr 26, 2024
Contributor
Thank you for sending the PR. It seems that the CI reports errors. |
redboltz
commented
Apr 26, 2024
Contributor
Fixed by #1120 , please rebase the PR. |
When `CMAKE_INSTALL_LIBDIR` and `CMAKE_INSTALL_INCLUDEDIR` are set to relative paths, the `msgpack-c.pc` file generated by CMake improperly configures `libdir` and `includedir`. This leads to incorrect paths that prevent the compiler from locating necessary header and library files.
Build and install `msgpack-c`.
```console
% git switch -c c_master
% cmake -S . -B ../msgpack-c.build -DCMAKE_INSTALL_PREFIX=/tmp/local -DCMAKE_INSTALL_LIBDIR=lib-relative -DCMAKE_INSTALL_INCLUDEDIR=include-relative
% cmake --build ../msgpack-c.build
% cmake --install ../msgpack-c.build/
```
Compile `example/simple_c.c` using installed msgpack-c.
The following error happens because the linker cannot find paths provided by pkg-config.
```console
% export PKG_CONFIG_PATH=/usr/local/lib-relative/pkgconfig:$PKG_CONFIG_PATH
% gcc -o simple_c example/simple_c.c $(pkg-config --cflags --libs msgpack-c)
/usr/bin/ld: cannot find -lmsgpack-c: No such file or directory
collect2: error: ld returned 1 exit status
```
Successly compile `example/simple_c.c` using install msgpack-c.
We can execute `simple_c.c` like the following.
```console
% gcc -o simple_c example/simple_c.c $(pkg-config --cflags --libs msgpack-c)
% ./simple_c
93 01 c3 a7 65 78 61 6d 70 6c 65
[1, true, "example"]
```
The generated `msgpack-c.pc` file does not handle relative paths correctly. Here is the result of the incorrect configuration in How to reproduce section.
In the following `msgpack-c.pc` file, `libdir` and `includedir` are relative to the current directory, leading to incorrect paths.
```console
cat ../msgpack-c.build/msgpack-c.pc
prefix=/tmp/local
exec_prefix=/tmp/local
libdir=lib-relative
includedir=include-relative
Name: MessagePack
Description: Binary-based efficient object serialization library
Version: 6.0.1
Libs: -L${libdir} -lmsgpack-c
Cflags: -I${includedir}
```
Modify the `msgpack-c.pc.in` file to ensure that `libdir` and `includedir` use absolute paths by prefixing them with ${prefix}/. This change addresses the issue by providing correct paths to the compiler and linker.otegamiforce-pushed
the
support-relative-path-for-pkg-config
branch
from
April 26, 2024 04:21
699cfa7 to
68cc50aCompareotegami
commented
Apr 26, 2024
Author
@redboltz Thank you so much for addressing it. I've just rebased it! |
This was referenced Jun 21, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
CMAKE_INSTALL_LIBDIRandCMAKE_INSTALL_INCLUDEDIRare set to relative paths, themsgpack-c.pcfile generated by CMake improperly configureslibdirandincludedir. This leads to incorrect paths that prevent the compiler from locating necessary header and library files.How to reproduce
Build and install
msgpack-c.Compile
example/simple_c.cusing installed msgpack-c. The following error happens because the linker cannot find paths provided by pkg-config.Expected
Successly compile
example/simple_c.cusing install msgpack-c. We can executesimple_clike the following.Explain the problem in detail
The generated
msgpack-c.pcfile does not handle relative paths correctly. Here is the result of the incorrect configuration in How to reproduce section. In the followingmsgpack-c.pcfile,libdirandincludedirare relative to the current directory, leading to incorrect paths.Solution
Modify the
msgpack-c.pc.infile to ensure thatlibdirandincludediruse absolute paths by prefixing them with ${prefix}/. This change addresses the issue by providing correct paths to the compiler and linker.