Skip to content

Fix paths in pkg-config file#556

Merged
jbeder merged 1 commit into
jbeder:masterfrom
jamiesnape:fix-pkg-config
Feb 2, 2018
Merged

Fix paths in pkg-config file#556
jbeder merged 1 commit into
jbeder:masterfrom
jamiesnape:fix-pkg-config

Conversation

@jamiesnape

@jamiesnape jamiesnape commented Feb 1, 2018

Copy link
Copy Markdown
Contributor

pkg-config should be giving absolute paths rather than relative paths.

Broken by dc9c750 and in 0.6.0. If it would be possible to cut a 0.6.1 release with this fix in it, it would be very much appreciated.

Before:

$ cat yaml-cpp.pc
libdir=lib
includedir=include

Name: Yaml-cpp
Description: A YAML parser and emitter for C++
Version: 0.6.0
Requires:
Libs: -L${libdir} -lyaml-cpp
Cflags: -I${includedir}
$ pkg-config --cflags yaml-cpp 
-Iinclude
$pkg-config --libs yaml-cpp 
-Llib -lyaml-cpp

After (for example with install prefix /usr/local):

$ cat yaml-cpp.pc 
prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: Yaml-cpp
Description: A YAML parser and emitter for C++
Version: 0.6.0
Requires:
Libs: -L${libdir} -lyaml-cpp
Cflags: -I${includedir}
$ pkg-config --cflags yaml-cpp 
-I/usr/local/include
$ pkg-config --libs yaml-cpp 
-L/usr/local/lib -lyaml-cpp

PTAL @jbeder.

pkg-config should be giving absolute paths rather than relative paths.
@jbeder

jbeder commented Feb 2, 2018

Copy link
Copy Markdown
Owner

Is there a way to automatically test stuff like this? It would be nice to avoid having these CMake changes breaking things.

@jamiesnape

Copy link
Copy Markdown
Contributor Author

Something like:

make install
mkdir /tmp/hello_world
cd /tmp/hello_world
cat << 'EOF' > hello_world.cpp
#include <yaml-cpp/yaml.h>
int main() {
  YAML::Node node = YAML::Node("Hello, World!");
  return 0;
}
EOF
$CXX hello_world.cpp -Wall -std=c++11 $(pkg-config --cflags yaml-cpp) $(pkg-config --libs yaml-cpp) -o hello_world_pkg_config
./hello_world_pkg_config

Though possibly that would still compile (with a warning from ld) if the install prefix were /usr/ or /usr/local.

To test cmake you could add something like:

make install
mkdir /tmp/hello_world
cd /tmp/hello_world
cat << 'EOF' > hello_world.cpp
#include <yaml-cpp/yaml.h>
int main() {
  YAML::Node node = YAML::Node("Hello, World!");
  return 0;
}
EOF
cat << 'EOF' > CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
project(hello_world)
find_package(yaml-cpp REQUIRED)
add_executable(hello_world_cmake hello_world.cpp)
target_link_libraries(hello_world_cmake yaml-cpp)
EOF
cmake .
make
./hello_world_cmake

@jamiesnape jamiesnape deleted the fix-pkg-config branch February 2, 2018 16:25
@jbeder

jbeder commented Feb 2, 2018

Copy link
Copy Markdown
Owner

I mean automatically; how do I write that test?

@jamiesnape

Copy link
Copy Markdown
Contributor Author

The quick way would be paste the above into a file my_bash_script, make it executable, and modify .travis.yml:

script:
  - make
  - test/run-tests
  - make install
  - ./my_bash_script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants