Discussion:
[Open Babel] how to use CMAKE_PREFIX_PATH with openbabel
Davide Olianas
2017-06-07 08:22:54 UTC
Permalink
Hello,

the openbabel version shipped with my distribution (ubuntu 16.04) is
quite old; I’d like to link my programs to the most recent one, which I
installed in |~/opt| using the option |CMAKE_INSTALL_PREFIX=~/opt|.

Sadly, the environment variable CMAKE_PREFIX_PATH doesn’t appear to be
used by |FindOpenBabel2.cmake|. I copied this module because OpenBabel
can’t be found by default (is this a packaging problem of the
distribution? If not, could it be possible to add |FindOpenBabel2.cmake|
to OpenBabel source such that package maintainers can add the module?)

You can clone this repo <https://github.com/davethecipo/ob24api> for a
minimal (not) working example. If you have vagrant installed, just run
|vagrant up| to set up a clean virtual machine. If you don’t use
vagrant, you can look |bootstrap.sh| for the commands to reproduce the
problem.

Thanks for any help,
Davide

​
Noel O'Boyle
2017-06-07 12:23:07 UTC
Permalink
Does it work if you define -DOPENBABEL2_INCLUDE_DIR and
-DOPENBABEL2_LIBRARIES directly?

I note that very few of the Find modules that come with CMake actually
use this variable. It's usually handled indirectly by pkgconfig via
-DPKG_CONFIG_USE_CMAKE_PREFIX_PATH=TRUE. I haven't tested whether this
fixes it for you, but I don't think it's a bug at our end, or a
feature we will implement.

- Noel
Post by Davide Olianas
Hello,
the openbabel version shipped with my distribution (ubuntu 16.04) is quite
old; I’d like to link my programs to the most recent one, which I installed
in ~/opt using the option CMAKE_INSTALL_PREFIX=~/opt.
Sadly, the environment variable CMAKE_PREFIX_PATH doesn’t appear to be used
by FindOpenBabel2.cmake. I copied this module because OpenBabel can’t be
found by default (is this a packaging problem of the distribution? If not,
could it be possible to add FindOpenBabel2.cmake to OpenBabel source such
that package maintainers can add the module?)
You can clone this repo for a minimal (not) working example. If you have
vagrant installed, just run vagrant up to set up a clean virtual machine. If
you don’t use vagrant, you can look bootstrap.sh for the commands to
reproduce the problem.
Thanks for any help,
Davide
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenBabel-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Davide Olianas
2017-06-07 15:14:02 UTC
Permalink
Post by Noel O'Boyle
Does it work if you define -DOPENBABEL2_INCLUDE_DIR and
-DOPENBABEL2_LIBRARIES directly?
I note that very few of the Find modules that come with CMake actually
use this variable. It's usually handled indirectly by pkgconfig via
-DPKG_CONFIG_USE_CMAKE_PREFIX_PATH=TRUE. I haven't tested whether this
fixes it for you, but I don't think it's a bug at our end, or a
feature we will implement.
Thanks for your help. I finally succeeded using
-DPKG_CONFIG_USE_CMAKE_PREFIX_PATH=TRUE, with just a small addition: I
need to export `~/opt` to both `LIBRARY_PATH` and `LD_LIBRARY_PATH`.

Setting -DOPENBABEL2_INCLUDE_DIR and -DOPENBABEL2_LIBRARIES on the other
hand doesn't work. What should I set those to?

cmake -DOPENBABEL2_INCLUDE_DIR=/home/davide/opt/include/openbabel-2.0/
-DOPENBABEL2_LIBRARIES=/home/davide/opt/lib/ ..
-- Found OpenBabel 2.2 or later: /home/davide/opt/lib
-- openbabel include dir: /usr/include/openbabel-2.0
-- openbabel 2 libraries /home/davide/opt/lib
-- Configuring done
WARNING: Target "ob24api" requests linking to directory
"/home/davide/opt/lib". Targets may link only to libraries. CMake is
dropping the item.
-- Generating done
-- Build files have been written to: /home/davide/progetti/ob24api/build



The compilation fails with the following error



***@davide-MS-7850:~/progetti/ob24api/build$ LC_ALL=C make
[ 50%] Linking CXX executable ob24api
CMakeFiles/ob24api.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x26): undefined reference to `OpenBabel::OBAtom::OBAtom()'
main.cpp:(.text+0x35): undefined reference to `OpenBabel::OBMol::OBMol()'
main.cpp:(.text+0x4e): undefined reference to
`OpenBabel::OBConversion::OBConversion(std::istream*, std::ostream*)'
main.cpp:(.text+0x62): undefined reference to
`OpenBabel::OBConversion::SetOutFormat(char const*)'
main.cpp:(.text+0x76): undefined reference to
`OpenBabel::OBAtom::SetType(char const*)'
main.cpp:(.text+0x91): undefined reference to
`OpenBabel::OBAtom::SetVector(double, double, double)'
main.cpp:(.text+0xaa): undefined reference to
`OpenBabel::OBMol::AddAtom(OpenBabel::OBAtom&)'
main.cpp:(.text+0xbe): undefined reference to
`OpenBabel::OBConversion::~OBConversion()'
main.cpp:(.text+0xcd): undefined reference to `OpenBabel::OBMol::~OBMol()'
main.cpp:(.text+0xdc): undefined reference to `OpenBabel::OBAtom::~OBAtom()'
main.cpp:(.text+0x101): undefined reference to
`OpenBabel::OBConversion::~OBConversion()'
main.cpp:(.text+0x115): undefined reference to `OpenBabel::OBMol::~OBMol()'
main.cpp:(.text+0x129): undefined reference to
`OpenBabel::OBAtom::~OBAtom()'
collect2: error: ld returned 1 exit status
CMakeFiles/ob24api.dir/build.make:94: recipe for target 'ob24api' failed
make[2]: *** [ob24api] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/ob24api.dir/all'
failed
make[1]: *** [CMakeFiles/ob24api.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Geoffrey Hutchison
2017-06-07 16:04:01 UTC
Permalink
Setting -DOPENBABEL2_INCLUDE_DIR and -DOPENBABEL2_LIBRARIES on the other hand doesn't work. What should I set those to?
cmake -DOPENBABEL2_INCLUDE_DIR=/home/davide/opt/include/openbabel-2.0/ -DOPENBABEL2_LIBRARIES=/home/davide/opt/lib/ ..
No, you want

cmake -DOPENBABEL2_INCLUDE_DIR=/home/davide/opt/include/ -DOPENBABEL2_LIBRARIES=/home/davide/opt/lib/

The "openbabel" bit is added automatically to the INCLUDE_DIR

-Geoff
Davide Olianas
2017-06-07 16:44:38 UTC
Permalink
Post by Geoffrey Hutchison
No, you want
cmake -DOPENBABEL2_INCLUDE_DIR=/home/davide/opt/include/ -DOPENBABEL2_LIBRARIES=/home/davide/opt/lib/
If I comment out the following two lines in my project CMakeLists.txt,

#set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
#find_package(OpenBabel2 REQUIRED)


I can compile with these commands

cmake -DOPENBABEL2_INCLUDE_DIR=/home/davide/opt/include/openbabel-2.0/
-DOPENBABEL2_LIBRARIES=/home/davide/opt/lib/libopenbabel.so ..

LIBRARY_PATH=~/opt:$LIBRARY_PATH make


Thanks to everyone!

Davide

David Hall
2017-06-07 15:53:45 UTC
Permalink
since FindOpenBabel2.cmake uses pkg-config, you can do something like

PKG_CONFIG_PATH=~/opt/lib/pkgconfig/ cmake ..

That said, I believe there may a better way to link to openbabel with cmake
using the files in:

~/opt/lib/cmake/openbabel2/

but I don't know what that is.

On Jun 7, 2017, at 4:22 AM, Davide Olianas <***@davideolianas.com> wrote:

Hello,

the openbabel version shipped with my distribution (ubuntu 16.04) is quite
old; I’d like to link my programs to the most recent one, which I installed
in ~/opt using the option CMAKE_INSTALL_PREFIX=~/opt.

Sadly, the environment variable CMAKE_PREFIX_PATH doesn’t appear to be used
by FindOpenBabel2.cmake. I copied this module because OpenBabel can’t be
found by default (is this a packaging problem of the distribution? If not,
could it be possible to add FindOpenBabel2.cmake to OpenBabel source such
that package maintainers can add the module?)

You can clone this repo <https://github.com/davethecipo/ob24api> for a
minimal (not) working example. If you have vagrant installed, just run vagrant
up to set up a clean virtual machine. If you don’t use vagrant, you can
look bootstrap.sh for the commands to reproduce the problem.

Thanks for any help,
Davide
​
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot______
Loading...