#Help adding a library to cmake.

251 messages · Page 1 of 1 (latest)

noble flare
#

Hello, I tried installing rabbitmq with the AMQPCPP library but i got an error: undefined reference to ... After some digging I saw that I need to add the library to cmake but kept getting problems since I didn't know what to add and how to use include with <> since I have never worked with plain c++ only Unreal Engine.

crisp saddleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

placid osprey
#

#tooling message

noble flare
#

So if you have any examples it would be great

placid osprey
#

I mean, I literally just gave you all the docs

#

try reading them

noble flare
#

I already did ive been trying to add it for 3 dats already

placid osprey
#

you read all those links and watched all those vids?

#

they have examples you know

#

because I'm wondering if your definition of "trying" is the same as mine

#

trying random shit is not the same as reading

noble flare
#

I think we have the same definition

placid osprey
#

I mean, idk what to tell you

#

I learned CMake before half of those docs existed

noble flare
#

the only thing i cant seem to find anywhere ifni have to include a .lib or the include folder but with bothbit cant seem to find it with#include <>

placid osprey
#

I see

#

so, this isn't a CMake issue

#

you have a lot to learn

#

but I'm probably not willing to hold your hand and explain all of this to you

#

maybe google for "c++ library howto"

#

idk

noble flare
#

Ofc

placid osprey
#

"c++ library tutorial", etc etc

noble flare
#

ok one question is creating a library adding a library since one of those docs onky has creating a library

placid osprey
#

you are not ready for the CMake docs yet, probably

#

so ignore them for now

#

learn how libraries work in C++ first

noble flare
#

k

placid osprey
#

the CMake documentation assumes you know this already

noble flare
#

I think that was were i was stuck

#

I have come to a discovery I needed to use .lib

#

And that brings me back to cmake again

hollow storm
#

If you clone this AMQPCPP library into your project structure, is it may just be a matter of your cmake adding:

add_subdirectory(amqpcpp)   # or whatever the directory name reads

target_link_directories(${PROJECT_NAME} PRIVATE amqpcpp)

The mere pulling in of this library will make yours inherit any include paths that this library exports.

noble flare
#
# The places to look for the tinyxml2 folders
set(FIND_AMQP-CPP_PATHS
        C:/AMQP-CPP                               # On Windows, this is where my tinyxml2 folder is
        ~/Libary/Frameworks/AMQP-CPP              # On Mac, this is where my tinyxml2 folder is
        )

# The location of the include folder (and thus the header files)
# find_path uses the paths we defined above as places to look
# Saves the location of the header files in a variable called TINYXML2_INCLUDE_DIR
find_path(AMQP-CPP_INCLUDE_DIR amqpcpp.h   # The variable to store the path in and the name of the header files
        PATH_SUFFIXES include               # The folder name containing the header files
        PATHS ${FIND_AMQP_CPP_PATHS})       # Where to look (defined above)

# The location of the lib folder (and thus the .a file)
# find_library uses the paths we defined above as places to look
# Saves the location of the .a file in a variable called TINYXML2_LIBRARY
find_library(AMQP-CPP_LIBRARY               # The variable to store where it found the .a files
        NAMES AMQP-CPP                      # The name of the .a file (without the extension and without the 'lib')
        PATH_SUFFIXES lib                   # The folder the .a file is in
        PATHS ${FIND_AMQP-CPP_PATHS})               # Where to look (defined above)``` This as a FindAMQP-CPP.CMAke
#
cmake_minimum_required(VERSION 3.23)
project(WebShop)

set(CMAKE_CXX_STANDARD 14)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") # CMAKE_CURRENT_LIST_DIR is the directory holding the CMakeLists.txt we are currently using

include_directories(src/backend/Basket)

add_executable(WebShop
        src/backend/Basket/basket.cpp
        src/backend/Basket/basket.h)


include(FindPkgConfig)
find_package(AMQP-CPP REQUIRED)
include_directories(${AMQP-CPP_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${AMQP-CPP_LIBRARY})
``` And this as my cmakelists but it still returned an error
#
Please set them or make sure they are set and tested correctly in the CMake files:
AMQP-CPP_INCLUDE_DIR
   used as include directory in directory C:/Users/front/OneDrive/Documents/WebShop
   used as include directory in directory C:/Users/front/OneDrive/Documents/WebShop
   used as include directory in directory C:/Users/front/OneDrive/Documents/WebShop
AMQP-CPP_LIBRARY
    linked by target "WebShop" in directory C:/Users/front/OneDrive/Documents/WebShop

CMake Error in CMakeLists.txt:
  Found relative path while evaluating include directories of "WebShop":

    "AMQP-CPP_INCLUDE_DIR-NOTFOUND"``` this the error i got if u interested @hollow storm
hollow storm
hollow storm
#

(full disclosure: I am cooking dinner and will be sporadic in replies)

noble flare
#

thats where i have my files located

#

this is my current file structure

noble flare
hollow storm
noble flare
hollow storm
#

I don't get it.
The website gives instructions on CMake, but I cannot see how you got AMQP from there.
Is there a link hiding somewhere?
Or is there another level of content if you sign up/in?

noble flare
#

like it says under every code snippet you can change .. tou your libraries language

hollow storm
#

Okay, but where did you get the AMQP libraries / code from?

noble flare
#

this is how the github thing looks fater compiling

hollow storm
#

Yes, but my point is that someone (don't know who - you are skirting around the question which is fine) is precompiling the library and wrote a Find.cmake file for it.
This latter file is probably not endorsed by the author(s) of the AMQP library.

#

That in itself is not a problem per se, but questions arise about the suitability of this Find.cmake file.

noble flare
#

if someone has it installed

#

wait my ass dumb af

#

in my program files cmake created one already

hollow storm
#

Does your CMakeLists.txt pull this in via find_package() and do you provide the path to this AMQP project via the CMAKE_PREFIX_PATH ?

noble flare
#

hwo can i make this space work?

hollow storm
noble flare
noble flare
hollow storm
#

That's fine.

noble flare
#

so the problem rn would be the space in the porgram files

#

would that be resolved with ""

hollow storm
noble flare
#

I think im missing it

hollow storm
#

Libary ---> Library

noble flare
#

Oh thanks

hollow storm
#

I don't think that it matters.

noble flare
#

fixed that

hollow storm
#

I think when you run cmake, you should run it with

cmake -DCMAKE_PREFIX_PATH="{path where AMQP-CPP is installed}"
#

That set() command that trips you up could be commented out.

noble flare
hollow storm
#

No, that file should be found by your find_package().
When it does, then a slew of CMake variables will get filled in.

noble flare
#

i did find a typo in the find

hollow storm
#

You are trying to donkey work that CMake normally does for you.

#

Keep in the back of your mind that CMake is meant to make things easier.

noble flare
noble flare
hollow storm
#

Hang on....

noble flare
#

I will, fixed that alr btw

#

the thing i dont get is this: CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: AMQP-CPP_INCLUDE_DIR used as include directory in directory C:/Users/front/OneDrive/Documents/WebShop used as include directory in directory C:/Users/front/OneDrive/Documents/WebShop used as include directory in directory C:/Users/front/OneDrive/Documents/WebShop

hollow storm
#
cmake -DCMAKE_PREFIX_PATH="{path where AMQP-CPP is installed}" -G "MinGW Makefiles" ...
noble flare
hollow storm
#

How sure of that are you?
Also, what if you wanted to try side-by-side versions of the AMQP library?

noble flare
hollow storm
#

If you are sure that AMQP is always installed in "that" directory for all devs then you are correct, you don't need to provide the command line option.
You could then instead add to your CMake file

set(CMAKE_PREFIX_PATH {path where AMQP-CPP is installed})

However, it still needs to read CMAKE_PREFIX_PATH because that's where find_package() will look.

Also, you may need more than one library, in which case these need to be provided via the same CMAKE _PREFIX_PATH but with a semi-colon in between each lib.

noble flare
hollow storm
#

Minus the {}.
Just use "".

noble flare
#

so this will be the new one minus th e{}

hollow storm
#

Just find_package(amqpcpp REQUIRED)
I think.

noble flare
#

Ok so one last question

hollow storm
#

Certainly do not add the prefix path into find_package()

noble flare
#

now how can i include the .h?

noble flare
#

#include <amqpcpp.h> this doesnt work

hollow storm
#

Well, if all goes to plan, then these variables that cmake says weren't found, are found.

noble flare
#

no errors

hollow storm
#

That's very good progress there!

#

Time for a little side adventure. Can you spare the time?

noble flare
#

Actually I have like 15 minutes left or so preferably less

hollow storm
#

I'll be quick.

noble flare
#

pretty late around here and have school tmrw

hollow storm
#

Hmmm, you must be east of where I live.

noble flare
#

Im in the netherlands so its almost 10 pm but i gotta wake up at 6 so ill prob go to bed earlier today

hollow storm
#

In your cmake file, add near the top

include(CMakePrintHelpers)
noble flare
#

thx

hollow storm
#

Further down, after the find_package() for AMQP, add

cmake_print_variables(AMQP-CPP_INCLUDE_DIR)
noble flare
#

prob still somewhere here or in temp

hollow storm
#

That should then print all the include paths that AMQP exports to your project.

#

With those you should probably find your best point to start your #include from.

For instance, where you put

#include <ampqcpp.h>

It may for instance need to read:

#include <include/ampqcpp.h>

That requires some investigation on your part.
I don't know what AMQP exports.

#

Once you've worked that out, then you can revert these include() and cmake_print_variables() instructions I had you add.

noble flare
#

I dont have AMQP-CPP_INCLUDE_DIR anymore

#

isnt that cmake_PREFIX_PATH NOW?

hollow storm
#

No, that is (hopefully) exported by the AMQP project.
You need that - or the correct variable - in your target_include_directories()

example:

target_include_directories(${PROJECT_NAME} PRIVATE ${AMQP-CPP_INCLUDE_DIR})
noble flare
#

cmake_print_variables(AMQP-CPP_INCLUDE_DIR)

#

-- AMQP-CPP_INCLUDE_DIR="AMQP-CPP_INCLUDE_DIR-NOTFOUND"

#

sorry wrong copy

hollow storm
#

I of course cannot see inside this Find.cmake file to work out what variables it exports.
I hope for your sake that there is documentation that came with it.

noble flare
#

since i thought you said i didnt need it anymore

hollow storm
noble flare
#

ooooh we have a prob

#

lemme see if i got my find somewhere around here

hollow storm
noble flare
#

that is a log

hollow storm
#

This variable that was "NOT FOUND"... where did you get its name from?

#

Is it used in your cmake file?

noble flare
#
# The places to look for the tinyxml2 folders
set(CMAKE_PREFIX_PATH C:/Progra~2/amqpcpp)

# The location of the include folder (and thus the header files)
# find_path uses the paths we defined above as places to look
# Saves the location of the header files in a variable called TINYXML2_INCLUDE_DIR
find_path(AMQP-CPP_INCLUDE_DIR amqpcpp.h   # The variable to store the path in and the name of the header files
        PATH_SUFFIXES include               # The folder name containing the header files
        PATHS ${FIND_AMQP_CPP_PATHS})       # Where to look (defined above)

# The location of the lib folder (and thus the .a file)
# find_library uses the paths we defined above as places to look
# Saves the location of the .a file in a variable called TINYXML2_LIBRARY
find_library(AMQP-CPP_LIBRARY               # The variable to store where it found the .a files
        NAMES AMQP-CPP                      # The name of the .a file (without the extension and without the 'lib')
        PATH_SUFFIXES lib                   # The folder the .a file is in
        PATHS ${FIND_AMQP-CPP_PATHS})               # Where to look (defined above)```
#

thats my cmake file

hollow storm
#

Part of it, surely?

#

Where is the find_package()

noble flare
#

not my cmakelists

#
include(CMakePrintHelpers)
project(WebShop)

set(CMAKE_CXX_STANDARD 14)

include_directories(src/backend/Basket)

add_executable(WebShop
        src/backend/Basket/basket.cpp
        src/backend/Basket/basket.h)

find_package(amqpcpp REQUIRED)
cmake_print_variables(AMQP-CPP_INCLUDE_DIR)
``` this is cmakelists
#
set(CMAKE_PREFIX_PATH C:/Progra~2/amqpcpp)

# The location of the include folder (and thus the header files)
# find_path uses the paths we defined above as places to look
# Saves the location of the header files in a variable called TINYXML2_INCLUDE_DIR
find_path(AMQP-CPP_INCLUDE_DIR amqpcpp.h   # The variable to store the path in and the name of the header files
        PATH_SUFFIXES include               # The folder name containing the header files
        PATHS ${FIND_AMQP_CPP_PATHS})       # Where to look (defined above)

# The location of the lib folder (and thus the .a file)
# find_library uses the paths we defined above as places to look
# Saves the location of the .a file in a variable called TINYXML2_LIBRARY
find_library(AMQP-CPP_LIBRARY               # The variable to store where it found the .a files
        NAMES AMQP-CPP                      # The name of the .a file (without the extension and without the 'lib')
        PATH_SUFFIXES lib                   # The folder the .a file is in
        PATHS ${FIND_AMQP-CPP_PATHS})               # Where to look (defined above)```this is FIndAMQP-CPP.cmake
hollow storm
#

Okay, can you run cmake over your CmakeLists file once more.
What does it print out?

noble flare
#

"C:\Program Files\JetBrains\CLion 2022.2.3\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2022.2.3/bin/ninja/win/ninja.exe" -G Ninja -S C:\Users\front\OneDrive\Documents\WebShop -B C:\Users\front\OneDrive\Documents\WebShop\cmake-build-debug
-- AMQP-CPP_INCLUDE_DIR="AMQP-CPP_INCLUDE_DIR-NOTFOUND"
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/front/OneDrive/Documents/WebShop/cmake-build-debug

[Finished]

#
-- AMQP-CPP_INCLUDE_DIR="AMQP-CPP_INCLUDE_DIR-NOTFOUND"
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/front/OneDrive/Documents/WebShop/cmake-build-debug

[Finished]
hollow storm
#

Hmmm.
Shall we park it here? I think you probably want to 💤

noble flare
#

I just really want to this to be done today since its been a pain in my asshole for the last few days

hollow storm
#

It's not complaining that it cannot find the package.
Yet, for some reason it is not filling in the AMQP-CPP_INCLUDE_DIR variable.

noble flare
#

I set it to amqpcpp.h

#

wait lets go over both files first and see if there a typo or something okay

#
include(CMakePrintHelpers)
project(WebShop)

set(CMAKE_CXX_STANDARD 14)

include_directories(src/backend/Basket)

add_executable(WebShop
        src/backend/Basket/basket.cpp
        src/backend/Basket/basket.h)

find_package(amqpcpp REQUIRED)
cmake_print_variables(AMQP-CPP_INCLUDE_DIR)``` This is my whole cmakelists.txt
hollow storm
noble flare
#

so what will my findAMQP LOOK LIe

hollow storm
#

You don't have one.
It should exist in the prefix path (CMAKE_PREFIX_PATH) which you set to "C:/Progra~2/amqpcpp".
That find file should live there.

noble flare
#

So the file can be deleted?

#

if i do amqp-cpp_INCLUDE_dire doesnt exist anymor

hollow storm
#

You shouldn't have it among your files, no.
But before you delete it, make sure it exists in that amqpcpp dir.

noble flare
#

this existst in there

#

although it has a different name i think

#

it has nothing with include dir

#

it is some config

hollow storm
#

as long as your CmakeLists.txt reads

find_package(amqpcpp REQUIRED)
noble flare
#

ok

#
project(WebShop)

set(CMAKE_CXX_STANDARD 14)

include_directories(src/backend/Basket)

add_executable(WebShop
        src/backend/Basket/basket.cpp
        src/backend/Basket/basket.h)

find_package(amqpcpp REQUIRED)``` so this should work
hollow storm
#

Those files are terribly complicated.
I have never written one myself. One day...

noble flare
#

Now the findamqp is not neccesary anymore

hollow storm
#

Yes, but you still need to set the CMAKE_PREFIX_PATH before find_package().
I am confused about where you set this.

noble flare
#

yes ok sorry

#
project(WebShop)

set(CMAKE_CXX_STANDARD 14)

include_directories(src/backend/Basket)

add_executable(WebShop
        src/backend/Basket/basket.cpp
        src/backend/Basket/basket.h)

set(CMAKE_PREFIX_PATH C:/Progra~2/amqpcpp)
find_package(amqpcpp REQUIRED)```
#

Like this?

#

only thing now is including amqp

#

then im done

#

i hope

#

and then i finally have anotyher commit

hollow storm
#

Does that variable AMQP-CPP_INCLUDE_DIR print out anything?

noble flare
#

amqp-ccp is something i made in my FindAMQP-CPP

hollow storm
#

Rather annoying.

hollow storm
#

Is there no documentation that came with this [redacted] amqpcppConfig.cmake file?

noble flare
#

nope

hollow storm
#

It's a wee bit naughty to just dump that on someone without documentation.

noble flare
#

is there any way i can know which one it is without doing the print cmake thing

hollow storm
#

How large is that file?
Can you C&P it here?

noble flare
#

c&P?

hollow storm
#

Copy & Paste

noble flare
#

i cant its huge

hollow storm
#

hang on...

noble flare
#

it is generated by cmake so prob no custom stuff in there

hollow storm
#

Can you grep that file for "INCLUDE"?

noble flare
#

WDYM

hollow storm
#

Find all occurrences of the word "INCLUDE" in that file.

#

grep is a Linux term.
Might be available in PowerShell. IDK.

noble flare
#

Create imported target amqpcpp

add_library(amqpcpp STATIC IMPORTED)

set_target_properties(amqpcpp PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "include/"
)

#

@hollow storm sorry im kinda in a hurry can u read ^^

hollow storm
#

It wouldn't be as generic as INTERFACE_INCLUDE_DIRECTORIES.

noble flare
#

thats everything that contains include

#

nothing else does

noble flare
#

Generated by CMake

hollow storm
#

Well, you could try (in yours)

cmake_print_variables(INTERFACE_INCLUDE_DIRECTORIES)
noble flare
#
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/front/OneDrive/Documents/WebShop/cmake-build-debug```
hollow storm
#

As I suspected.

noble flare
#

but it isnt NOTFOUND so it did got into the folder

#

get*\

hollow storm
#

To get yourself out of a pickle right now, you could of course do

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_PREFIX_PATH})

This will add "C:/Progra~2/amqpcpp" as a location for header files.

Any #include for AMQP stuff would be relative to that.

noble flare
#

nwo how do i get ti that

#

i still cant do #Include <> and type that in

#

o r""

hollow storm
#

Warning, I noticed you also had in your CmakeLists.txt

include_directories(src/backend/Basket)

So I would revise my earlier suggestion to

target_include_directories(${PROJECT_NAME}
   PRIVATE src/backend/Basket
   PRIVATE ${CMAKE_PREFIX_PATH})
hollow storm
noble flare
#

yes

#

amqpcpp.h

hollow storm
#

So in your shell, cd to "C:/Progra~2/amqpcpp"
Then run

dir /s {header fname}
noble flare
#

i dont have linux

#

wait lemme try powershell

hollow storm
#

That should find the file and print out the path to it.
Say it reads

amqcpp/include/amqcpp.h

Then that is what you type in your code.

noble flare
#

dir : Cannot find path 'C:\s' because it does not exist.

hollow storm
hollow storm
#

Maybe try explorer.
That has a search option.

#

Kids these days.
Cannot even use the console. Tut. 😅

noble flare
#

I don't use the console that often for something else than git

#

or mkdir ls etc

hollow storm
#

"ls" is a linux command.
"dir" on windows.

Anyway, in the console "dir /s" searches in subdirs. FYI.

noble flare
#

its weird on some devices i have linux some windows so i get like all mixed up

#

but ill go

#

thanks for your help today

hollow storm
#

Did you find it?
Or are we parking this?

crisp saddleBOT
#

@noble flare Has your question been resolved? If so, run !solved :)

hollow storm
#

If you are picking this up in the morning or sometime after that.
You should find your header file(s) somewhere in that directory "C:/Progra~2/amqpcpp"

Note their locations relative to "C:/Progra~2/amqpcpp".

Example, file "amqp.h" lives in dir "C:/Progra~2/amqpcpp/amqp/include"

Then in your code, you should:

#include <amqp/include/amqp.h>

That should theoretically work.

noble flare
#

ok thanks i will try that in this case it woll in include/amqpcpp.h only thing is yesterday i did that and it gave an error

crisp saddleBOT
#

@noble flare Has your question been resolved? If so, run !solved :)

hollow storm
#

Yes, but you probably didn't have this in your CMakeLists.txt then?

target_include_directories(${PROJECT_NAME}
   PRIVATE src/backend/Basket
   PRIVATE ${CMAKE_PREFIX_PATH})
#

Again, this is a workaround because you and I were unable to work out which variables the AMQP-CPP config exported.

hollow storm
#

Can you recap...
What is the issue right now?

crisp saddleBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.