How to link Poco library(libraries) to our program in unix environment
Asked Answered
S

3

13

I'm having trouble with Poco libraries. I need a simple solution to make the compilation easier. Is there any pkg-config file for Poco library to use it into our make files? Or any alternative solution?

Currently I use Ubuntu GNU/Linux.

I'm trying to use poco libraries in my app, but I don't know how to link Poco libraries to it. In fact I don't know how many libraries should be linked against the app. I want to know if there is an easy way to do it, such as using pkg-config files, as we do with gtkmm, for example:

g++ prog.cc `pkg-config --gtkmm-2.4 --libs --cflags` -o prog

and the pkg-config program appends appropriate libs and header files to our command.

Servile answered 22/3, 2010 at 8:35 Comment(3)
Are you having problems with compiling Poco itself or your programs with Poco?Alane
Trouble with programs with poco.Servile
@SepDev - You haven't given a lot to go on. Simpler than what? What are you currently doing? You can re-edit your question to provide more information.Alane
A
17

I don't think Poco comes with any pre-packaged ".pc" files but you should be able to create your own easily and stick them in the lib/pkgconfig directory on your system if you prefer that method.

I don't know exactly where you installed Poco on your system so you may have to do a "find" to locate your files. To compile you need to specify the poco header directory, the poco library directory, and the individual poco libraries. So something like:

g++ -I<path-to-poco-include-dir> -o prog prog.cpp -L<path-to-poco-lib-dir> -l<some-poco-lib> -l<another-poco-lib> 

For example:

g++ -I/usr/local/Poco/include -o prog prog.cpp -L/usr/local/Poco/lib -lPocoFoundation -lPocoNet  -lPocoNetSSL -lPocoUtil -lPocoXML

There are 20 or so different poco .so files so you obviously need to link the proper ones. Poco makes this pretty easy since the library names conform to the documentation sections - e.g. util stuff is in libPocoUtil.so. If you also compiled debug versions of the libraries they will end in 'd' - e.g. libPocoUtild.so

Again, once you locate all your files you may prefer to create your own poco.pc since you should have the information you need to create it.

Alane answered 30/3, 2010 at 2:10 Comment(0)
P
6

On ubuntu 16.04 you'll first need to install Poco libraries accordingly, that is done as follows:

sudo apt install libpoco-dev

Then you'll need to add the proper instructions to the linker, it will depend on the includes you have, for example if you used

#include <Poco/Net/MailMessage.h>

You'll need the following switches:

-lPocoNet -lPocoFoundation

ej:

g++ main.cpp -Wall -std=c++11 -o pocotest -lPocoNet -lPocoFoundation
Pergola answered 14/8, 2017 at 2:37 Comment(0)
P
0

Here's a command line that is working for me after building static libraries with vcpkg:

g++ --verbose -std=c++17 \
-I $(pwd)/vcpkg/installed/x64-linux/include \
-I $(pwd)/base \
-D POCO_STATIC \
main.cpp \
Application.cpp \
Database.cpp DatabaseRecord.cpp \
base/HttpServer.cpp \
base/UtilityClasses.cpp \
base/Utilities.cpp \
-L./vcpkg/installed/x64-linux/lib \
-lPocoEncodings -lPocoJSON -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation \
-lsqlite3 -lcurl -lexpat -lturbojpeg -lminiz -lpng -lz -lpcre2-posix -lpcre2-8 -lpcre2-16 -lpcre2-32 -lssl -lcrypto \
-o myapp
Pentagon answered 10/8 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.