3

I want to use this lib DuckX. I followed tutorial,

git clone https://github.com/amiremohamadi/DuckX.git
cd DuckX
mkdir build
cd build
cmake ..
cmake --build .

It went on without any error. However, when I entered sample directory and execute g++ sample1.cpp -lduckx, it got the following error message,

sample1.cpp:1:10: fatal error: duckx.hpp: No such file or directory
 #include "duckx.hpp"
          ^~~~~~~~~~~
compilation terminated.

I wonder how I can successfully use this lib. Could you please tell me what I can do to make the program use this lib. Thanks.

si yan
  • 343
  • 1
  • 13
  • you need to provide the include path on the command line with `-I`, you'll probably need the lib path too with `-L` – Alan Birtles Jan 18 '21 at 14:50
  • Did you check if this .hpp file were installed somewhere? – Damien Jan 18 '21 at 15:00
  • @Damien: The CMakeLists.txt file of DuckX does have an install section, so it goes in the "usual" location. See https://cmake.org/cmake/help/v3.0/module/GNUInstallDirs.html – MSalters Jan 18 '21 at 15:02
  • @MSalters The fact that a given file should have been installed at a given location doesn't always mean that it has been really installed! Moreover, the Duckx documentation provides an example with an alternative: `#include ` – Damien Jan 18 '21 at 15:08
  • @Alan Birtles: I add -I with include path, it did not report an error about head files. I am not sure the lib path is where the `libduckx.a` locate. Now it says something error about the `lduckx`, it says `/usr/bin/ld: cannot find -lduckx`. – si yan Jan 18 '21 at 15:09
  • @siyan: As the comment syas, you need `-I` for the **I**nclude and `-L` for the **L**inker – MSalters Jan 18 '21 at 15:13
  • @Damien: I find the duckx.hpp file is in the `DuckX/include`. I use `-I` to identify where the include files are. It works but now the error is that the compiler report errors `/usr/bin/ld: cannot find -lduckx` – si yan Jan 18 '21 at 15:13
  • @MSalters: I am not sure the path after `-L`. I suppose the lib is `libduckx.a`. `libduckx.a` is in the `DuckX/build`. I add this path but the compiler report that many errors like this `sample1.cpp:(.text+0x89): undefined reference to 'duckx::Document::open()'` – si yan Jan 18 '21 at 15:20
  • @siyan: The build step of CMake puts it in `DuckX/build`, but the later install step probably makes a copy into your system directories. Did that happen? It's probably somewhere under `/usr/lib`. You might want to pass `-Wl,--verbose` to check what `ld` is doing. – MSalters Jan 18 '21 at 15:25
  • @MSalters note that following the instructions on the linked github page wont run the install step as it just does `cmake --build .` rather than `cmake --build . --target install` – Alan Birtles Jan 18 '21 at 15:30
  • @AlanBirtles: That actually sounds like the answer. – MSalters Jan 18 '21 at 16:33
  • @MSalters: I add `-L` option with the path of the directory and the `libduckx.a` path. It works. – si yan Jan 19 '21 at 02:34

0 Answers0