pistacheio / pistache

A high-performance REST toolkit written in C++
https://pistacheio.github.io/pistache/
Apache License 2.0
3.18k stars 698 forks source link

Can someone describe the process of installing Pistache on Centos 6.5 etc #582

Closed Asimov500 closed 4 years ago

Asimov500 commented 5 years ago

I have actually finished my program and it does exactly what I want, but I have been doing it in codeblocks on a Ubuntu system. So now I want to run my program on a Centos headless server. I have made a Makefile and my Makefile works on Ubuntu without errors, but then pistache is installed.

So I was wondering if someone could talk me through the process of installing Pistache on Centos. Is there a yum command to install pistache or do I just clone pistache from git and use the Makefile to build it and then copy the pistache folder to my project?

Bear in mind I am new to linux and I usually do everything in windows, so if my question sounds stupid then that is why.

dennisjenkins75 commented 5 years ago

There is no install package for RedHat/Centos. The only Linux distro with a package manager that knows about pistache is Debian (Ubuntu also?), due to Kip's efforts. Personally, I develop on Gentoo Linux and install pistache without using Gentoo's package manager. Someday we'll have a gentoo ebuild for pistache, but its not a priority for me right now.

For Centos, right now, you just need to build and install pistache using our build docs. I assume that it will install into /usr/local, but idk what centos will do.

You might want to consider building a Ubuntu-based docker image that runs your app, and then running that on Centos.

Asimov500 commented 5 years ago

Thanks I will try that. I have heard of docker, but not had any experience with it. Our works server runs on centos so I have to use what they have got, and it isn't up to me what they run.

Asimov500 commented 5 years ago

Well I think I failed at the first hurdle. I couldn't get cmake to work in centos as it kept complaining it wasn't the latest version. So installed cmake3 and used the line cmake3 -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .. and unfortunately I got a lot of errors.

-- Configuring incomplete, errors occurred!
See also "/home/thomas/pistache/build/CMakeFiles/CMakeOutput.log".
See also "/home/thomas/pistache/build/CMakeFiles/CMakeError.log".
[root@centos build]# cmake3 -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
-- Configuring done
CMake Error in src/CMakeLists.txt:
  Target "pistache" requires the language dialect "CXX14" , but CMake does
  not know the compile flags to use to enable it.

CMake Error in src/CMakeLists.txt:
  Target "pistache_shared" requires the language dialect "CXX14" , but CMake
  does not know the compile flags to use to enable it.

CMake Error in src/CMakeLists.txt:
  Target "pistache_static" requires the language dialect "CXX14" , but CMake
  does not know the compile flags to use to enable it.

So it looks like it is not possible to compile pistache in centos, which is a shame as I have put a lot of work into it, and my server works great in ubuntu.

I think I will have to start looking for another libary which works with centos, as I am only an average C++ programmer so I probably wouldn't be able to work out how to change it to make it work with centos.

However I will say that pistache is a good libary and will definately recommend it as long as they ain't using centos of course LOL.

dennisjenkins75 commented 5 years ago

Pistache requires c++14, a dialect of C++.

What is the output of "g++ --version" on your centos system?

You need to install c++14 or c++17 support (eg, g++-7 or greater, iirc).

Asimov500 commented 5 years ago

My output from g++ --version is this

[root@centos build]# g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23)

I will look into upgrading my c++ to 14 or 17, gotta google how to do that.

mohsenomidi commented 5 years ago

the lowest version of g++ that support the C++14 is 4.9 you should upgrade your compiler. you can use the yum package manager on CentOS to do this, you can find many instructions of upgrading or installing the latest version of gcc in the internet.

Asimov500 commented 5 years ago

I have updated gcc now, but I still get the same errors on the cmake gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5) It is still complaing that I need c++14 even though I have updated gcc now. I actually wish I knew what I was doing LOL.

Asimov500 commented 5 years ago

I actually got it to compile so to help anyone else with the same problem I will describe what I did to get it to work in centos. If you have already made the build folder then delete it and start again, and remake it. I found that the files that are in there which were created before I updated gcc stopped it compiling again. So if you have already had a go and failed then delete and mkdir build again.

First of all install gcc yum install gcc-c++

However this version of gcc won't work with pastich as it installs an older version. So next you have to get this version updated. Now you might not need to do the first step but I am writing what I did in case. So next I installed the devtoolset like this.

sudo yum install centos-release-scl
sudo yum install devtoolset-7-gcc*
scl enable devtoolset-7 bash
which gcc
gcc --version

So at this point your gcc compiler should now be updated.

First of all cmake won't work on centos if you have just freshly installed it. If you install cmake using yum it installs an old version which won't work with pistache. You have to force it to install cmake3 with the following lines.

sudo yum install epel-release
sudo yum install cmake3
ls -l /usr/bin/cmake3

Now basically you can follow the instructions on this page http://pistache.io/quickstart

The only difference is that you have to run cmake3 instead of cmake.

cd pistache
mkdir build
cd build
cmake3 -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
make
sudo make install

I haven't tried running the server yet as I have only just got centos to include without error so far. If you keep this thread open for a couple of days I will see if I can get the server to run ok.

So far I have got this to compile

#include "pistache/router.h"
#include "pistache/endpoint.h"
#include "pistache/http.h"
#include <iostream>

using namespace std;

int main()
{
      std::cout << "include working" << std::endl;
}

Going to try a small code example next, but I am tired after a long day at work, so give me a couple of days and I will let you know if I get the rest of the code to compile.

Asimov500 commented 5 years ago

I am afraid that even though I think pistache is compiled on centos I cannot get it to run. I have used the simple example from the pistache page. eg

#include "pistache/endpoint.h"

using namespace Pistache;

class HelloHandler : public Http::Handler {
public:

    HTTP_PROTOTYPE(HelloHandler)

    void onRequest(const Http::Request& request, Http::ResponseWriter response) override{
        UNUSED(request);
        response.send(Pistache::Http::Code::Ok, "Hello World\n");
    }
};

int main() {
    Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(9080));
    auto opts = Pistache::Http::Endpoint::options()
        .threads(1);

    Http::Endpoint server(addr);
    server.init(opts);
    server.setHandler(Http::make_handler<HelloHandler>());
    server.serve();
}

And here is my make file

NAME = myprogram
CFLAGS = -c -lpistache -lpthread
output: main.o
    g++ main.o -o $(NAME)

main.o: main.cpp
    g++ $(CFLAGS) main.cpp

clean:
    rm *.o myprogram

Unfortunately when I compile I get a page full of errors. I won't post all the errors as it goes on for a couple of pages, so I will just show the top ten lines.

main.cpp:(.text+0x13b): undefined reference to `Pistache::Port::Port(unsigned short)'
main.cpp:(.text+0x14a): undefined reference to `Pistache::IP::any()'
main.cpp:(.text+0x193): undefined reference to `Pistache::Address::Address(Pistache::IP, Pistache::Port)'
main.cpp:(.text+0x1a3): undefined reference to `Pistache::Http::Endpoint::options()'
main.cpp:(.text+0x1b4): undefined reference to `Pistache::Http::Endpoint::Options::threads(int)'
main.cpp:(.text+0x1ee): undefined reference to `Pistache::Http::Endpoint::Endpoint(Pistache::Address const&)'
main.cpp:(.text+0x207): undefined reference to `Pistache::Http::Endpoint::init(Pistache::Http::Endpoint::Options const&)'
main.cpp:(.text+0x23c): undefined reference to `Pistache::Http::Endpoint::setHandler(std::shared_ptr<Pistache::Http::Handler> const&)'
main.cpp:(.text+0x263): undefined reference to `Pistache::Http::Endpoint::serve()'

So I am guessing that it either hasn't compiled correctly or I haven't done something right to make it work. I even tried copying the pistache folder into my project folder and the include folder. Then I tried copying the libaries in eg libpistache.a and libpistache.so into the folder.

I really think I am clutching at straws at the moment, but I am utterly stuck at the moment. I wonder if I am the only one who has tried to get it working in centos?

Asimov500 commented 5 years ago

Ok I have managed to update g++ to 4.91 updated my Makefile by adding this CFLAGS = -std=c++14 -lnet -c - lpistache -lpthread and a lot of errors have gone away that I had before. However I am still getting a lot of undefined reference errors when I attempt to compile. I have put some of the errrors, here but there are literary pages of errors. I have no idea what I am doing g++ -std=c++0x -lnet -c -lpistache -lpthread main.cpp

In file included from /usr/local/include/pistache/listener.h:13,
                 from /usr/local/include/pistache/endpoint.h:9,
                 from main.cpp:1:
/usr/local/include/pistache/async.h:15:18: error: atomic: No such file or direct                                                                                      ory
In file included from /usr/local/include/pistache/tcp.h:12,
                 from /usr/local/include/pistache/listener.h:9,
                 from /usr/local/include/pistache/endpoint.h:9,
                 from main.cpp:1:
/usr/local/include/pistache/flags.h:44: error: expected ‘;’ before ‘bool’
In file included from /usr/local/include/pistache/listener.h:10,
                 from /usr/local/include/pistache/endpoint.h:9,
                 from main.cpp:1:
/usr/local/include/pistache/net.h: In constructor ‘Pistache::AddrInfo::AddrInfo(                                                                                      )’:
/usr/local/include/pistache/net.h:36: error: ‘nullptr’ was not declared in this                                                                                       scope
/usr/local/include/pistache/net.h: In member function ‘int Pistache::AddrInfo::i                                                                                      nvoke(const char*, const char*, const addrinfo*)’:
Asimov500 commented 5 years ago

I have finally got it to compile, but not with a makefile, but with the following line. g++ -std=c++14 main.cpp -o main -lpistache -lpthread

However when I run the compiled program I get an error. error while loading shared libraries: libpistache.so.0 cannot open shared object file: No such file or directory.

So I found the libpistache.so.0 library and copied it into the same folder, but I got the same error.

I don't know why I can compile using the line above but my Makefile doesn't work eg

NAME = myprogram
CFLAGS = -std=c++14 -c -lpistache -lpthread
output: main.o
    g++ main.o -o $(NAME)

main.o: main.cpp
    g++ $(CFLAGS) main.cpp 

clean:
    rm *.o myprogram

I hope my posts help somebody else get it to work, but so far it is not working for me in centos.

win32asm commented 5 years ago

However when I run the compiled program I get an error. error while loading shared libraries: libpistache.so.0 cannot open shared object file: No such file or directory.

So I found the libpistache.so.0 library and copied it into the same folder, but I got the same error.

When compiling myprogram add linker options to search for the library in known places, e.g.: CFLAGS = -std=c++14 -c -lpistache -lpthread -Wl,-rpath,./ -Wl,-rpath,/usr/lib64/

Also on CentOS 7 you can use "more modern" c/c++ from SCL (https://wiki.centos.org/SpecialInterestGroup/SCLo)

yum install centos-release-scl
yum install devtoolset-8-toolchain
# without next line toolset would not be exposed into current env
echo "source scl_source enable devtoolset-8" >> ~/.bashrc

rh7 usage ref. (same commands & packages, another repos): https://developers.redhat.com/blog/2019/03/05/yum-install-gcc-8-clang-6/

mohsenomidi commented 4 years ago

this issue does not exist any more and Pistache can be compiled. we can close this issue

Asimov500 commented 4 years ago

I never did get this working unfortunately. I can understand you closing old posts though, but I never got it working. Tried my hardest, but failed. Probably because I am not an expert linux user. It is a shame because it worked great in Ubuntu.

mohsenomidi commented 4 years ago

Ok, lets check in cenos, i will do it in next few weeks after CentOs installation on my machine , will feedback..we can keep it open

Asimov500 commented 4 years ago

Will be great if you set out the steps to get it compiled and working. I am using centos6.5. I know it is a little old, but it is what our company uses. If it was my way I would use a newer version however. I am mainly a windows user who dabbles in linux occasionally. I mess about with a raspberry pi and ubuntu mainly. Only recently installed centos to match our companies server. Thanks for looking into it.

kiplingw commented 4 years ago

If someone wants to prepare RPM metadata as a PR, that would likely solve his problem.

win32asm commented 4 years ago

Well, the problem here is that C7 and C6 use gcc compiler/std library too old to compile a proper c++11 code, and C8 compiles pistache out of the box.

I don't think that an RPM for supporting C6/C7 makes sense, especially because compiling requires setting up additional (official) repositories.

Let me try on a clean C6.5, I will post exact sequence of steps to get to compiling it.

win32asm commented 4 years ago

on a clean newly installed centos 6.5 system:

yum update
# otherwise SSL comm would fail
yum install epel-release centos-release-scl
# to have access to cmake3 and modern gcc - and install them
yum install cmake3 devtoolset-8-{gcc,gcc-c++}
# fetch & compile pistache
git clone https://github.com/oktal/pistache.git
mkdir -p pistache/build
cd pistache/build
scl enable devtoolset-8 -- cmake3 ../
scl enable devtoolset-8 -- make -j 10

note that you'll have to build your own binaries using scl enable devtoolset-8 -- <build command> and the binaries will (may) have a dependency on devtoolset-8-runtime

There's no way to build or use pistache with "default" gcc & cmake on CentOS below 8

dennisjenkins75 commented 4 years ago

Does anyone want to attempt to add CentOS 8 (or whatever is most recent) support to our travis config?

kiplingw commented 4 years ago

Dennis, as I've suggested many times before, for proper continuous integration testing for particular distros, Travis really isn't the way to do it. For CentOS, Fedora, or other distros we need to be using whatever their analogue to DEP-8 is. Likely in order to prepare for that, someone needs to patch in distro related packaging files (e.g. spec for RPM).

dennisjenkins75 commented 4 years ago

Kip, you are very Debian focused. IDK what dep-8 is. I do not understand why you think that building pistache in a CentoOS travis instance won't help catch some redhatisms that affect the viability of a code change. There should be nearly nothing in pistache that cares about the actual linux distro, but I've been surprised before. Also, travis is the tool that we have right now. We currently use it to check the build across different versions of the two main OSS compilers. But building against CentOS image will prove that pistache can successfully compile on said OS. So when ppl show up and file bugs saying "shit's broke, yo" we can point them to the travis config and say "it works in our canonical test infrastructure, compare that with your build environment." I fail to see why you are against this.

kiplingw commented 4 years ago

Dennis, yes I am Debian focused. That is why I said if you are testing building for a specific distro then you should start with the continuous integration tool for that distro or family of distros. For Debian based systems we use Autopkgtest. However, Autopkgtest simply implements the DEP-8 standard which is not Debian specific. It's universal. Take a look.

Travis cannot achieve anywhere near the functionality of anything that implements DEP-8. You have much less ability to control the replicability of the build and unit testing environment with Travis than you do with a better engineered continuous integration tool. This is the reason why Google, Canonical, Walt Disney, Wells Fargo, etc. all uses DEP-8 based CI. Travis is fine if you just want to verify that code compiled after every commit.

Asimov500 commented 4 years ago

@win32asm win32asm

on a clean newly installed centos 6.5 system:

yum update
# otherwise SSL comm would fail
yum install epel-release centos-release-scl
# to have access to cmake3 and modern gcc - and install them
yum install cmake3 devtoolset-8-{gcc,gcc-c++}
# fetch & compile pistache
git clone https://github.com/oktal/pistache.git
mkdir -p pistache/build
cd pistache/build
scl enable devtoolset-8 -- cmake3 ../
scl enable devtoolset-8 -- make -j 10

note that you'll have to build your own binaries using scl enable devtoolset-8 -- <build command> and the binaries will (may) have a dependency on devtoolset-8-runtime

There's no way to build or use pistache with "default" gcc & cmake on CentOS below 8

Ok I followed this process and everything seemed to compile ok and lots of thanks. What is the next step I need to do, to compile the example code after doing this.

Bear in mind in ubuntu I have completed my project, but I want to know how to go about compiling a simple example before porting over my project from ubuntu. In ubuntu I have written it in codeblocks but in centos6.5 I am using a headless system so will have to make the Makefiles myself.

I am not new to programming, but I am new to linux. I do dabble with linux, but I am like a lost sheep most of the time.

win32asm commented 4 years ago

note that you'll have to build your own binaries using scl enable devtoolset-8 -- <build command> and the binaries will (may) have a dependency on devtoolset-8-runtime There's no way to build or use pistache with "default" gcc & cmake on CentOS below 8

Ok I followed this process and everything seemed to compile ok and lots of thanks. What is the next step I need to do, to compile the example code after doing this.

@Asimov500 - I propose you to create a separate repo with sample project and a build script (incorporating the proposed way to fetch & compile pistache), and invite me to provide guidance on further actions, to keep this issue pistache-specific.

@kiplingw , @dennisjenkins75 - I will try to provide an RPM to build packages in CentOS-specific way. Would libpistache and libpistache-devel be appropriate names for library and development packages?

kiplingw commented 4 years ago

@win32asm win32asm Bear in mind in ubuntu I have completed my project, but I want to know how to go about compiling a simple example before porting over my project from ubuntu. In ubuntu I have written it in codeblocks but in centos6.5 I am using a headless system so will have to make the Makefiles myself.

@win32asm, if you are using Ubuntu and you don't need to actually modify the Pistache source, just use the precompiled packages in the PPA. After you've installed them use pkg-config to automatically have your build environment use the correct compiler and linker flags.

kiplingw commented 4 years ago

@kiplingw , @dennisjenkins75 - I will try to provide an RPM to build packages in CentOS-specific way. Would libpistache and libpistache-devel be appropriate names for library and development packages?

Yes. That appears to fit with what I know of the RedHat based distro nomenclature. Be sure to also generate a debugging symbol package as we do already when generating debs. This is useful for people who may be having issues with the library.

kiplingw commented 4 years ago

A list of continuous integration (CI) tools on other distros available here.

Asimov500 commented 4 years ago

@win32asm I can't show you the real actual project, so I will make a small test project in ubuntu and share it on github, but give me a few days to do this, as I have a lot of work to get through over the next couple of days. I don't know how to use scl enable devtoolset-8 to make the binaries at the moment. I also don't know what the PPA thing is that kiplingw mentioned. I usually use codeblocks in windows, so it was easier for me to use codeblocks in ubuntu. I originally wrote the program in windows. Then got it working in ubuntu and then added pistache to do the server stuff.

I am a linux novice I am afraid and just about know the basics.

win32asm commented 4 years ago

@win32asm ...I will make a small test project in ubuntu and share it on github...

OK. please do.

I also don't know what the PPA thing is that @kiplingw mentioned.

https://launchpad.net/~kip/+archive/ubuntu/pistache-unstable see "Adding this PPA to your system" section. This would allow you to install libpistache0 and pistache-dev packages and your ubuntu test project wouldn't require building pistache locally.

Asimov500 commented 4 years ago

Hi @win32asm I have added my codeblocks test server to github. Now this compiles in codeblocks fine and the server runs. Basically it is not much different to the examples on the Pistache webpage. https://github.com/Asimov500/simple-codeblocks-server The problem is that I can compile and run the server in codeblocks fine in Ubuntu, which is why I have put the codeblocks version on github, but if I try and use a Makefile it fails, Really the only file you need is the main.cpp, and a Makefile that works. My makefile below fails, and I suspect it is because I need to set some kind of path to pistache or something. My Makefile I tried was this

NAME = myprogram
CFLAGS = -st=c++14 -c -lpistache -lpthread
output: main.o
     g++ main.o -o $(NAME)

main.o: main.cpp
    g++ $(CFLAGS) main.cpp

clean:
    rm *.o myprogram
kiplingw commented 4 years ago

@Asimov500, please don't place compiler and linker flags directly into your makefile for Pistache. The required ones could changes from time to time. This is why it is best to use pkg-config. This is an international standard that simplifies building and improves portability.

$ pkg-config --cflags --libs libpistache
-I/usr/include// -L/usr/lib/x86_64-linux-gnu// -lpistache -lpthread -lssl -lcrypto

What you want to do in your makefile is set CFLAGS like so:

CFLAGS=-std=c++14 $(pkg-config --cflags --libs libpistache)

There is a pkg-config manifest that is automatically installed on your system when you install the libpistache-dev package from the PPA.

xinthose commented 4 years ago

I set the library paths in my Makefile like so:

LFLAGS = -L/usr/local/lib -L/usr/lib
ifeq ($(32_BIT_CPU),1)
    LFLAGS += -Llib -L/usr/lib/i386-linux-gnu -L/lib/i386-linux-gnu
else
    LFLAGS += -L64_lib -L/usr/lib/x86_64-linux-gnu -L/lib/x86_64-linux-gnu

My whole Makefile.

kiplingw commented 4 years ago

CFLAGS=-std=c++14 $(pkg-config --cflags --libs libpistache)

Sorry, CFLAGS should only contain pkg-config --cflags, wheras LDFLAGS should use --libs.

Everyone should be using pkg-config, regardless of which distro you are using. It's a much safer, simpler, and portable way of ensuring your build environment has the correct paths, compiler, and linker flags at build time.

Asimov500 commented 4 years ago

@kiplingw Bear in mind if I compile this code in codeblocks it compiles fine and works, but my Makefile still fails even after adding the package line. My github link is above. CFLAGS=-std=c++14 $(pkg-config --cflags --libs libpistache) Here is an image showing some of the errors I get when I try to compile with a Makefile. compilerErrors

win32asm commented 4 years ago

@Asimov500: Bear in mind if I compile this code in codeblocks it compiles fine and works, but my Makefile still fails even after adding the package line. My github link is above. CFLAGS=-std=c++14 $(pkg-config --cflags --libs libpistache)

Let's move the makefile discussion into your repo 8-) To be short, you have to separate compile and link stages, and provide proper flags to each of them.

kiplingw commented 4 years ago

@Asimov500 as I mentioned CFLAGS and LDFLAGS should be separate. Show us what the following outputs on your command line:

pkg-config --cflags --libs libpistache

If you see nothing, it's probably because you didn't install the development package:

sudo apt install libpistache-dev

Asimov500 commented 4 years ago

@kiplingw After running the line I got -I/usr/local/include// -L/usr/local/lib// -lpistache -lpthread After running sudo apt install libpistache-dev I got

Reading package lists done
Building dependancy tree
Reading state information ... done
E: Unable to located package libpistache-dev

@win32asm I have messaged you in the repo. @kiplingw The reason for the Makefile is so I could test it works with the Makefile, and the next stage I need to get it working Centos. I can actually compile it fine in Ubuntu using codeblocks. I have as @win32asm suggested started a thread for that in the repo.

kiplingw commented 4 years ago

@Asimov500 it looks like you have a local copy of Pistache installed into the local file hierarchy standard prefix. This is not recommended and is unsafe. Unless you are intending to work on Pistache source, use a precompiled package.

You don't need to compile Pistache if you just want to use it. And even if you do need to compile it yourself, you should not install it system wide outside of a package manager. This can cause all kinds of problems with artefacts that don't get cleaned up and aren't tracked by apt.

Your package manager needs to add the Pistache unstable PPA. Look in the ReadMe.md for instructions on how to add that. The most recent packages are built for 19.10 (Eoan) which I recommend.

Asimov500 commented 4 years ago

@kiplingw I installed it by following these instructions http://pistache.io/quickstart thinking that was the correct way. Like I said I have no problem compiling from codeblocks, but not from the Makefile. I am mainly a windows user who dabbles in linux, so I am a long long way from being an expert. I am trying to learn.

If I have done it wrong, then perhaps I didn't follow the instructions on that page correctly then. Although I did do every step. I am truely a beginner. Most of my program was written in windows, then I ported it over to linux and then added the pistache stuff. However what I have put on github is just a test.

kiplingw commented 4 years ago

Hey @Asimov500. Sorry, but please don't use the website for the time being. Everything on there is really old. @dennisjenkins75 and I have been trying to get those page updated for a while but @oktal is AWOL.

Please use the ReadMe.md here.

Asimov500 commented 4 years ago

Oh I didn't know that the instructions were wrong. I have to work out how to uninstall the old pistache and install the new one. Will the PPA version work with Codebocks? As that is my IDE of choice. The only reason I was trying to use Makefiles is to port it from Ubuntu to Centos.

I run Ubuntu in virtualbox, so I might make a new one and try out the PPA version of pistache. PS. I have just tried the Makefile that @win32asm gave me and that worked, which is good.

kiplingw commented 4 years ago

Codeblocks is just an IDE. Think of it as a fancy text editor. As long as the underlying compiler can find the Pistache headers and libraries, you are fine. The standard cross-platform way this is done is with pkg-config.

Once you have Ubuntu Eoan (19.10) installed, add the unstable PPA and the packages from the repository. You'll be up and running in no time.

Asimov500 commented 4 years ago

I have now compiled my program using the pkg_config. Thanks to @win32asm for that. It would be good to have the Makefile that @win32asm made for me in some kind of wiki, as it is so mind bogglingly useful for a beginner like myself.

kiplingw commented 4 years ago

@win32asm, I think @Asimov500's suggestion is a good one. If you'd like to consider submitting a PR for README.md to add under the 'Use via pkg-config' section, that would likely help him and others. The Autotools example could be one subsection of examples.

joaofouyer commented 1 year ago

I was able to get Pistache work in a Debian-based machine but I could not make it work under CentOS, even after following the instructions described in this issue by @Asimov500.

I guess the project and the docs has changed since then. So tried to clone and build it with Meson, as described in here.

My CMakeLists.txt:

cmake_minimum_required(VERSION 3.17.2)
project(my_project)

set(CMAKE_CXX_STANDARD 17)

find_package(PkgConfig)
pkg_check_modules(Pistache REQUIRED IMPORTED_TARGET libpistache)

add_executable(my_project main.cpp Server.cpp Server.h Endpoint.cpp Endpoint.h)
target_link_libraries(my_project PkgConfig::Pistache)

The error I get when I try to build with cmake3 -S. -Bbuild

-- Checking for module 'libpistache'
--   No package 'libpistache' found
CMake Error at /usr/share/cmake3/Modules/FindPkgConfig.cmake:497 (message):
  A required package was not found
Call Stack (most recent call first):
  /usr/share/cmake3/Modules/FindPkgConfig.cmake:681 (_pkg_check_modules_internal)
  CMakeLists.txt:8 (pkg_check_modules)

-- Configuring incomplete, errors occurred!

When I run find / -iname libpistache.so I can find it under /usr/local/lib64/libpistache.so. The same with find / -iname libpistache.pc, where I get the output /usr/local/lib64/pkgconfig/libpistache.pc.

I also tried to manually set the CMAKE_PREFIX_PATH following these instructions but no success.

Lastly, I tried to manually set the path of the .so file that I cloned in my CMakeLists.txt

set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /thcs/fouyer/pistache/build/src/libpistache.so)
cmake_minimum_required(VERSION 3.17.5)
project(my_project)

set(CMAKE_CXX_STANDARD 17)

add_library(Pistache SHARED IMPORTED GLOBAL)
set_target_properties(Pistache PROPERTIES IMPORTED_LOCATION /thcs/fouyer/pistache/build/src/libpistache.so)

add_executable(my_project main.cpp Server.cpp Server.h Endpoint.cpp Endpoint.h)
target_link_libraries(my_project Pistache)

Could someone give some advice on how to make Pistache work on CentOS with CMake?

joaofouyer commented 1 year ago

I forgot to metion that in the last approach, when I run cmake3 -S. -Bbuild I can run successfully and get the output:

-- Configuring done
-- Generating done
-- Build files have been written to: /home/thcs/fouyer/my-project/build

But when I try to build the executable with cmake3 --build build I get:

gmake[2]: *** No rule to make target `/thcs/fouyer/pistache/build/src/libpistache.so', needed by `my_project'.  Stop.
gmake[1]: *** [CMakeFiles/my_project.dir/all] Error 2
gmake: *** [all] Error 2
kiplingw commented 1 year ago

Sorry to hear about your troubles @joaofouyer. I don't believe anyone has attempted to prepare RPM packages for Pistache yet, which would be easier for you to work with than building from source (unless you need to). Obviously there are people who would benefit from RPMs.

Is this something you'd be interested in providing a PR for?

Tachi107 commented 1 year ago

Hi @joaofouyer, what does running pkg-config --cflags --libs libpistache in your shell output?

joaofouyer commented 1 year ago

Hi @joaofouyer, what does running pkg-config --cflags --libs libpistache in your shell output?

It outputs that it wasn't found.

Package libpistache was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpistache.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libpistache' found

So I tried export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig (because it was the output of find / -iname libpistache.pc) and I could build it with CMake and then run the executable. Thank you, @Tachi107!