Vcoder
Vcoder

Reputation: 124

How can i compile a project with libqrencode?

I am trying to compile this code but it always gives me "Undefined reference to QRcode_encodeString and QRcode_free". I have done the ./configure, make and make install, no errors where shown. I have no idea what flags i need to use in other to compile it. I'm currently using slackware 3.10 i686. I'm only trying to compile with gcc -Wall main.c. I'm still trying to understand linux libraries and shared objects. Any clue to what might be the problem? My source code is in the same directory as the qrencode.h file. I tried #include and "qrencode.h".

Upvotes: 2

Views: 1712

Answers (1)

Tim Čas
Tim Čas

Reputation: 10867

You're forgetting to link with your library.

In other words, the compiler knows what to do with the code (since you're including the header and so on), but the linker does not (since it doesn't "know" where to find the implementation of that --- you need to tell it!).

Add -lqrencode to your compiler flags. If the library is in some directory not searched by default, you also need to add -L/path/to/libdir.

This may be of some help (it gives a few examples for compiling and linking): https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html

One additional node: The linker is already involved in building your program: It links your separate object files (assuming you have multiple *.c files) into one. It also it links with at least libc; however, that library is special in that GCC links it implicitly (that is, you don't have to say -lc), since it's the C standard library.

Upvotes: 4

Related Questions