#Help adding a library to cmake.
251 messages · Page 1 of 1 (latest)
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.
#tooling message
for some reason i dont understand Cmake for a bit
So if you have any examples it would be great
I already did ive been trying to add it for 3 dats already
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
I think we have the same definition
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 <>
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
Ofc
and you know, get creative, try googling for many similar things
"c++ library tutorial", etc etc
ok one question is creating a library adding a library since one of those docs onky has creating a library
you are not ready for the CMake docs yet, probably
so ignore them for now
learn how libraries work in C++ first
k
the CMake documentation assumes you know this already
I think that was were i was stuck
I have come to a discovery I needed to use .lib
Since I use clion I keep getting this when i search how to add a library on clion https://intellij-support.jetbrains.com/hc/en-us/articles/206558149-How-do-I-add-my-libraries-to-the-project-
And that brings me back to cmake again
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.
After some digging I found if it wanted to opensource it there was a better weay to do that so I'll show you real quick what I found
# 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
Where does this FindAMQP-CPP.cmake file come from?
It's not provided by the authors, right?
I mean, I am looking at https://github.com/CopernicaMarketingSoftware/AMQP-CPP
It isn't I got it from lemonoats.com
(full disclosure: I am cooking dinner and will be sporadic in replies)
ok np
thats where i have my files located
this is my current file structure
If ya need any more info lemme know
Cannot find that.
DDG failure?
Learn how to create static libraries and link to them in CLion with CMake.
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?
Nope. That is just showing how I can use cmake and add libraries so I took that example and put all the things of amqp-cpp in there
like it says under every code snippet you can change .. tou your libraries language
Okay, but where did you get the AMQP libraries / code from?
the include is given and the .lib is compiled
this is how the github thing looks fater compiling
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.
But I'm not claiming it's mine its just a simple way of finding it
if someone has it installed
wait my ass dumb af
in my program files cmake created one already
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 ?
yes it does
I saw a snippet of the CmakeFile here:#1029815334624047245 message
It does not show find_package().
prohb didnt copy the whole thing mb
That's fine.
so the problem rn would be the space in the porgram files
would that be resolved with ""
There is a typo in this, btw.
I think im missing it
Libary ---> Library
Oh thanks
I don't think that it matters.
It says it does:
CMake Warning (dev) at cmake/FindAMQP-CPP.cmake:3:
Syntax Warning in cmake code at column 31
Argument not separated from preceding token by whitespace.```
fixed that
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.
That did work only shouldnt the FindAMQP_CPP.cmake do this automatically?
No, that file should be found by your find_package().
When it does, then a slew of CMake variables will get filled in.
i did find a typo in the find
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.
my .lib was called amqpcpp instead of AMQP-CPP
Yes that's, true but now my CMakeLists doesnt work anymore since that cmake command made some files with VS 2022 instead of mingw
Hang on....
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
cmake -DCMAKE_PREFIX_PATH="{path where AMQP-CPP is installed}" -G "MinGW Makefiles" ...
but isnt that possible with cmakefiles since for people who use my source code they dont need to do that if it is installed in the standard location
How sure of that are you?
Also, what if you wanted to try side-by-side versions of the AMQP library?
what do you mean by side by side
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.
set(CMAKE_PREFIX_PATH {C:/Progra~2/amqpcpp}) so this woould be correct
Minus the {}.
Just use "".
so this will be the new one minus th e{}
Just find_package(amqpcpp REQUIRED)
I think.
Ok so one last question
Certainly do not add the prefix path into find_package()
now how can i include the .h?
that was kinda dumb of me
#include <amqpcpp.h> this doesnt work
Well, if all goes to plan, then these variables that cmake says weren't found, are found.
no errors
That's very good progress there!
Time for a little side adventure. Can you spare the time?
Actually I have like 15 minutes left or so preferably less
I'll be quick.
pretty late around here and have school tmrw
Hmmm, you must be east of where I live.
Im in the netherlands so its almost 10 pm but i gotta wake up at 6 so ill prob go to bed earlier today
In your cmake file, add near the top
include(CMakePrintHelpers)
Goedenavond in dat geval.
thx
Further down, after the find_package() for AMQP, add
cmake_print_variables(AMQP-CPP_INCLUDE_DIR)
didnt you say i didnt need the findamqp-cpp.cmake naymore?
prob still somewhere here or in temp
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.
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})
cmake_print_variables(AMQP-CPP_INCLUDE_DIR)
-- AMQP-CPP_INCLUDE_DIR="AMQP-CPP_INCLUDE_DIR-NOTFOUND"
sorry wrong copy
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.
the problem is it doesnt exist anymore
since i thought you said i didnt need it anymore
Hope not.
I meant that you didn't need this:
#1029815334624047245 message
that is a log
This variable that was "NOT FOUND"... where did you get its name from?
Is it used in your cmake file?
# 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
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
Okay, can you run cmake over your CmakeLists file once more.
What does it print out?
"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]
Hmmm.
Shall we park it here? I think you probably want to 💤
i can do some more minutes
I just really want to this to be done today since its been a pain in my asshole for the last few days
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.
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
If that is in your CMakeLists.txt then you shouldn't have to do that.
find_package(amqpcpp) should do that.
so what will my findAMQP LOOK LIe
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.
You shouldn't have it among your files, no.
But before you delete it, make sure it exists in that amqpcpp dir.
this existst in there
although it has a different name i think
it has nothing with include dir
it is some config
as long as your CmakeLists.txt reads
find_package(amqpcpp REQUIRED)
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
Those files are terribly complicated.
I have never written one myself. One day...
Now the findamqp is not neccesary anymore
Yes, but you still need to set the CMAKE_PREFIX_PATH before find_package().
I am confused about where you set this.
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
Does that variable AMQP-CPP_INCLUDE_DIR print out anything?
no cause it still doesnt exist
amqp-ccp is something i made in my FindAMQP-CPP
Rather annoying.
Ah!
Is there no documentation that came with this [redacted] amqpcppConfig.cmake file?
nope
It's a wee bit naughty to just dump that on someone without documentation.
is there any way i can know which one it is without doing the print cmake thing
How large is that file?
Can you C&P it here?
c&P?
Copy & Paste
i cant its huge
hang on...
it is generated by cmake so prob no custom stuff in there
Can you grep that file for "INCLUDE"?
WDYM
Find all occurrences of the word "INCLUDE" in that file.
grep is a Linux term.
Might be available in PowerShell. IDK.
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 ^^
It wouldn't be as generic as INTERFACE_INCLUDE_DIRECTORIES.
it is generated
Generated by CMake
Well, you could try (in yours)
cmake_print_variables(INTERFACE_INCLUDE_DIRECTORIES)
its empty
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/front/OneDrive/Documents/WebShop/cmake-build-debug```
As I suspected.
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.
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})
Do you know the name of the header file you need to include?
So in your shell, cd to "C:/Progra~2/amqpcpp"
Then run
dir /s {header fname}
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.
dir : Cannot find path 'C:\s' because it does not exist.
with "" OR <>
Doesn't matter, but I would go with <>
Maybe try explorer.
That has a search option.
Kids these days.
Cannot even use the console. Tut. 😅
"ls" is a linux command.
"dir" on windows.
Anyway, in the console "dir /s" searches in subdirs. FYI.
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
Did you find it?
Or are we parking this?
@noble flare Has your question been resolved? If so, run !solved :)
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.
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
@noble flare Has your question been resolved? If so, run !solved :)
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.
i have that
Can you recap...
What is the issue right now?
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.