Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg-config does not work on conda #1422

Closed
ischoegl opened this issue Jan 11, 2023 · 3 comments
Closed

pkg-config does not work on conda #1422

ischoegl opened this issue Jan 11, 2023 · 3 comments
Labels

Comments

@ischoegl
Copy link
Member

Problem description

An attempt to compile the very simple C++ program using the pkg-config route fails.

Steps to reproduce

  1. Saved very simple C++ program as simple.cpp
  2. Run the following
% export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/homebrew/Caskroom/miniforge/base/envs/cantera-dev/lib
% export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/homebrew/Caskroom/miniforge/base/envs/cantera-dev/lib/pkgconfig
% g++ simple.cpp -o myProgram $(pkg-config --cflags --libs cantera)
% ./myProgram
dyld[92219]: Library not loaded: @rpath/libsundials_cvodes.6.dylib
  Referenced from: <E62AB15F-607D-3047-996E-A59885DCC71C> /Volumes/Data/work/GitHub/cantera/myProgram
  Reason: tried: '/System/Volumes/Preboot/Cryptexes/OS@rpath/libsundials_cvodes.6.dylib' (no such file), '/usr/local/lib/libsundials_cvodes.6.dylib' (no such file), '/usr/lib/libsundials_cvodes.6.dylib' (no such file, not in dyld cache)
zsh: abort      ./myProgram

System information

  • Cantera version: 3.0.0a3
  • OS: macOS
  • Python/MATLAB/other software versions: conda environment

Attachments

cantera.pc has the following content:

prefix=/opt/homebrew/Caskroom/miniforge/base/envs/cantera-dev
exec_prefix=${prefix}/bin
libdir=${prefix}/lib
includedir=${prefix}/include

Name: Cantera
Description: Cantera library
URL: https://cantera.org
Version: 3.0.0a3

Libs: -L${libdir} -L/opt/homebrew/Caskroom/miniforge/base/envs/cantera-dev/lib -L/opt/homebrew/Caskroom/miniforge/base/envs/cantera-dev/lib/python3.10/config-3.10-darwin -L/opt/homebrew/Caskroom/miniforge/base/envs/cantera-dev/lib -lcantera -lsundials_cvodes -lsundials_ida -lsundials_nvecserial -lsundials_sunlinsollapackdense -lsundials_sunlinsollapackband -lfmt -lyaml-cpp -lpython3.10 -ldl
Cflags: -std=c++14 -framework Accelerate -I${includedir} -I/opt/homebrew/Caskroom/miniforge/base/envs/cantera-dev/include -I

Additional context

Issue arose in the context of #1385

@ischoegl ischoegl added the macOS label Jan 11, 2023
@ischoegl ischoegl removed the macOS label Jan 11, 2023
@ischoegl ischoegl changed the title pkg-config does not work on conda/macOS pkg-config does not work on conda Jan 11, 2023
@ischoegl
Copy link
Member Author

With shared libraries introduced in Cantera 3.0.0a4, the library can now be linked with cantera_shared, which causes a somewhat different error:

% g++ simple.cpp -o myProgram $(pkg-config --cflags --libs cantera_shared)
Package cantera_shared was not found in the pkg-config search path.
Perhaps you should add the directory containing `cantera_shared.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cantera_shared' found
simple.cpp:1:10: fatal error: 'cantera/base/Solution.h' file not found
#include "cantera/base/Solution.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

A fix requires renaming cantera.pc to cantera_shared.pc, and using shared libraries rather than static libraries.

@ischoegl ischoegl added the bug label Mar 13, 2023
@speth
Copy link
Member

speth commented Jun 21, 2023

Given the improvements to handling the shared library, and the fact that using it is required for features like ExtensibleRate, I'm thinking we should just have pkg-config --libs cantera return flags suitable for linking to the shared library.

@speth
Copy link
Member

speth commented Jun 30, 2023

After some recent updates, pkg-config mostly works. That is, the command:

g++ kinetics1.cpp -o kinetics1 $(pkg-config --cflags --libs cantera)

produces an executable with no warnings. Two minor issues remain.

  1. Running the program requires providing information about the library path, either at run time:
LD_LIBRARY_PATH=$CONDA_PREFIX/lib ./kinetics1

or by recompiling with the RPATH embedded:

g++ kinetics1.cpp -o kinetics1 $(pkg-config --cflags --libs cantera) -Wl,-rpath,$CONDA_PREFIX/lib

This second solution can be baked into the cantera.pc file, of course.

Second, a path that only existed on the system where the package was built ends up in the cantera.pc file as an "include directory, e.g. -isystem /usr/share/miniconda3/conda-bld/cantera-recipe_1687996688861/_build_env/include. It would be nice to get rid of this, but it doesn't actually hurt anything.

speth added a commit to speth/cantera that referenced this issue Jul 1, 2023
speth added a commit to speth/cantera that referenced this issue Jul 1, 2023
speth added a commit to speth/cantera that referenced this issue Jul 1, 2023
@speth speth closed this as completed in be63409 Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

No branches or pull requests

2 participants