Adding Boost to Creator
-
I have lines such as
#include<boost/algorithm/string.hpp>
I add
INCLUDEPATH += /usr/include/boost
or
INCLUDEPATH += /usr/include/
to my .pro file
but it still errors out saying no file or directory. What is the problem?
-
@A123
usr/include/boost/algorithm
is a relative path. We need to know an absolute one. I will assume you mean/usr/include/boost/algorithm
In that case to find
<boost/algorithm/string.hpp>
you will needINCLUDEPATH += /usr/include/
. Which it may already have, andg++
should be looking in/usr/include
anyway.From a terminal copy & paste
ls -l /usr/include/boost/algorithm/string.hpp
and show the output.
-
@A123
usr/include/boost/algorithm
is a relative path. We need to know an absolute one. I will assume you mean/usr/include/boost/algorithm
In that case to find
<boost/algorithm/string.hpp>
you will needINCLUDEPATH += /usr/include/
. Which it may already have, andg++
should be looking in/usr/include
anyway.From a terminal copy & paste
ls -l /usr/include/boost/algorithm/string.hpp
and show the output.
-
if boost is installed as /usr/include/boost then your .pro file should not require any tweaking at all.
#include <boost/whatever.hpp>
should be adequate since /usr/include is a default search area.
Only place it gets mucky is when the chosen boost classes are not completely implemented as header file templates...such as boost::filesystem::
and cannot remember whether the preprocessor requires a space after #include. You don't have one.
-
if boost is installed as /usr/include/boost then your .pro file should not require any tweaking at all.
#include <boost/whatever.hpp>
should be adequate since /usr/include is a default search area.
Only place it gets mucky is when the chosen boost classes are not completely implemented as header file templates...such as boost::filesystem::
and cannot remember whether the preprocessor requires a space after #include. You don't have one.
@Kent-Dorfman said in Adding Boost to Creator:
cannot remember whether the preprocessor requires a space after #include.
My GCC 11.3 does not require a space. YMMV
if boost is installed as /usr/include/boost then your .pro file should not require any tweaking at all.
This is certainly the case on my Ubuntu machine. Nothing new required in the PRO file for that particular Boost header-only component.
Including </usr/include/boost/filesystem.hpp>, or any other Boost component that must be compiled separately, and attempting to use any function within will generate link time errors like this:
g++ -Wl,-O1 -o tt main.o /usr/lib/x86_64-linux-gnu/libQt5Gui.so /usr/lib/x86_64-linux-gnu/libQt5Core.so -lGL -lpthread /usr/bin/ld: main.o: in function `main': main.cpp:(.text.startup+0xa7): undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)' collect2: error: ld returned 1 exit status make: *** [Makefile:190: tt] Error 1
This is possibly what @A123 is seeing.
These Boost components will requireLIBS += -lboost_filesystem
or similar to function.
@A123: If you cannot work it out, please post all the Boost-related #includes and the actual error message(s) with a small amount of context.
-
@Kent-Dorfman said in Adding Boost to Creator:
cannot remember whether the preprocessor requires a space after #include.
My GCC 11.3 does not require a space. YMMV
if boost is installed as /usr/include/boost then your .pro file should not require any tweaking at all.
This is certainly the case on my Ubuntu machine. Nothing new required in the PRO file for that particular Boost header-only component.
Including </usr/include/boost/filesystem.hpp>, or any other Boost component that must be compiled separately, and attempting to use any function within will generate link time errors like this:
g++ -Wl,-O1 -o tt main.o /usr/lib/x86_64-linux-gnu/libQt5Gui.so /usr/lib/x86_64-linux-gnu/libQt5Core.so -lGL -lpthread /usr/bin/ld: main.o: in function `main': main.cpp:(.text.startup+0xa7): undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)' collect2: error: ld returned 1 exit status make: *** [Makefile:190: tt] Error 1
This is possibly what @A123 is seeing.
These Boost components will requireLIBS += -lboost_filesystem
or similar to function.
@A123: If you cannot work it out, please post all the Boost-related #includes and the actual error message(s) with a small amount of context.
@ChrisW67 said in Adding Boost to Creator:
@A123: If you cannot work it out, please post all the Boost-related #includes and the actual error message(s) with a small amount of context.
Offending code sample (missing string.hpp)
Error List
Top of .pro file
Location of boost files...ex string.hpp
Build environment
-
@A123
There is something we do not understand going on here. In principle given that you have#include<boost/algorithm/string.hpp>
it should be picking that up/usr/include/boost/algorithm/string.hpp
.Please open a terminal somewhere (some other empty directory within your
/home
area). Createfile.cpp
containing just:#include <boost/algorithm/string.hpp>
(It should make no difference, but I have put a space before the
<
). Now just type ing++ -c file.cpp
What do you get?
Then try:
g++ -c -I/usr/include fred.cpp
Now try changing the
<..>
to"..."
, i.e.#include "boost/algorithm/string.hpp"
with that second command-line again.Finally, try
#include "/usr/include/boost/algorithm/string.hpp"
, so the-I...
argument is irrelevant.Obviously we are only interested in what the compiler has to say about the
#include
line. I have suggested 4 things to try here. Do any of these work? Which work/fail? -
@A123
There is something we do not understand going on here. In principle given that you have#include<boost/algorithm/string.hpp>
it should be picking that up/usr/include/boost/algorithm/string.hpp
.Please open a terminal somewhere (some other empty directory within your
/home
area). Createfile.cpp
containing just:#include <boost/algorithm/string.hpp>
(It should make no difference, but I have put a space before the
<
). Now just type ing++ -c file.cpp
What do you get?
Then try:
g++ -c -I/usr/include fred.cpp
Now try changing the
<..>
to"..."
, i.e.#include "boost/algorithm/string.hpp"
with that second command-line again.Finally, try
#include "/usr/include/boost/algorithm/string.hpp"
, so the-I...
argument is irrelevant.Obviously we are only interested in what the compiler has to say about the
#include
line. I have suggested 4 things to try here. Do any of these work? Which work/fail? -
All work to generate file.o except
g++ -c -I/usr/include fred.cpp which has no such file or directory
g++ -c -I/usr/include fred.cpp which has no such file or directory
Well, that somehow looks like the situation you seem to be in from Creator.
What I really don't get is you are saying
g++ -c file.cpp
does work, while
g++ -c -I/usr/include fred.cpp
does not. Please confirm this is indeed exactly the case? It is vital we are 100% clear on this.
Now that is weird, because the
-I...
only adds directories to search. Since you say it worked OK without this I cannot understand how adding could prevent the file being found.Next test:
g++ -c -I/rubbish file.cpp # then does this work or fail??
I also asked you to try changing the
#include
from<...>
to"..."
. Did you do that? I am only interested if that made it behave differently in any case? -
g++ -c -I/usr/include fred.cpp which has no such file or directory
Well, that somehow looks like the situation you seem to be in from Creator.
What I really don't get is you are saying
g++ -c file.cpp
does work, while
g++ -c -I/usr/include fred.cpp
does not. Please confirm this is indeed exactly the case? It is vital we are 100% clear on this.
Now that is weird, because the
-I...
only adds directories to search. Since you say it worked OK without this I cannot understand how adding could prevent the file being found.Next test:
g++ -c -I/rubbish file.cpp # then does this work or fail??
I also asked you to try changing the
#include
from<...>
to"..."
. Did you do that? I am only interested if that made it behave differently in any case?I have file.cpp in sampleproject in the home directory. There is no fred.cpp file.
g++ -c -I/usr/include fred.cpp
gives me
cc1plus: fatal error: fred.cpp: No such file or directory compilation terminated.
g++ -c file.cpp
works to generate file.o
g++ -c -I/rubbish file.cpp
works
changing from <> to "" surrounding the include works.
I tried to start a new project in QT creator with file.cpp and the boost include was still not picked up.
In addition there is no usr/include in the system PATH variable when Iecho $PATH
Not sure if that matters
This is Linux Mint 21 BTW
-
I have file.cpp in sampleproject in the home directory. There is no fred.cpp file.
g++ -c -I/usr/include fred.cpp
gives me
cc1plus: fatal error: fred.cpp: No such file or directory compilation terminated.
g++ -c file.cpp
works to generate file.o
g++ -c -I/rubbish file.cpp
works
changing from <> to "" surrounding the include works.
I tried to start a new project in QT creator with file.cpp and the boost include was still not picked up.
In addition there is no usr/include in the system PATH variable when Iecho $PATH
Not sure if that matters
This is Linux Mint 21 BTW
@A123
OK, I'm tired. Whenever I wrotefile.cpp
orfred.cpp
they were supposed to be the same thing. I will try to stick tofile.cpp
.There are 4 combinations to try
g++ -c -I/usr/include file.cpp # where file.cpp contains <...> g++ -c -I/rubbish file.cpp # where file.cpp contains <...> g++ -c -I/usr/include file.cpp # where file.cpp contains "..." g++ -c -I/rubbish file.cpp # where file.cpp contains "..."
Can you clearly & unequivocally state which of these work and which fail?
Now that you say plain
g++ -c file.cpp
works then why did you ever start adding things toINCLUDEPATH
, that means it should have worked from the very start with nothing added? -
I'm really beginning to sense a corrupted g++ compiler instance here. The stuff being described just shouldn't happen!
-
@A123
OK, I'm tired. Whenever I wrotefile.cpp
orfred.cpp
they were supposed to be the same thing. I will try to stick tofile.cpp
.There are 4 combinations to try
g++ -c -I/usr/include file.cpp # where file.cpp contains <...> g++ -c -I/rubbish file.cpp # where file.cpp contains <...> g++ -c -I/usr/include file.cpp # where file.cpp contains "..." g++ -c -I/rubbish file.cpp # where file.cpp contains "..."
Can you clearly & unequivocally state which of these work and which fail?
Now that you say plain
g++ -c file.cpp
works then why did you ever start adding things toINCLUDEPATH
, that means it should have worked from the very start with nothing added?There are 4 combinations to try
All 4 generate file.o
Now that you say plain g++ -c file.cpp works then why did you ever start adding things to INCLUDEPATH, that means it should have worked from the very start with nothing added?
I was trying to get things to work from the QT creator IDE which still doesn't work. When I tried things out through terminal like you suggested it is able to find the boost library for the simple example. So I think the problem is some setting within QT creator itself.
For reference I am using QT creator 8.0.1, QT 6.3.1, and the QT6 Kit
-
There are 4 combinations to try
All 4 generate file.o
Now that you say plain g++ -c file.cpp works then why did you ever start adding things to INCLUDEPATH, that means it should have worked from the very start with nothing added?
I was trying to get things to work from the QT creator IDE which still doesn't work. When I tried things out through terminal like you suggested it is able to find the boost library for the simple example. So I think the problem is some setting within QT creator itself.
For reference I am using QT creator 8.0.1, QT 6.3.1, and the QT6 Kit
@A123 said in Adding Boost to Creator:
All 4 generate file.o
OK. Not sure that was the impression I got previously, but I get it now. That ought to be a good start!
So I think the problem is some setting within QT creator itself.
Creator does not do compiling itself. It is an IDE which calls on external tools (e.g.
g++
) to do compilations.Let's start by being 100.000% clear. Your screenshot shows errors. Do you indeed get these when you COMPILE ? If you only get these when looking at your source code in the IDE, not when you actually compile, now is the time to say so! That would be a totally different situation.... So please make this crystal clear?
Assuming you get them when you allow Creator to invoke the compiler. Then in principle there are really/mostly only two things in Creator which affect this:
-
Show the actual command-line being issued to compile the file. You can find this in Creator on the Compiler Output pane.
-
There is a Build Environment setting. That allows environment variables to be passed to the compiler which we do not see on its command-line. Do you have anything of interest there?
You could show these two.
One other random thought: you do not have a sub-directory named
boost
in, say, your source directory, or perhaps one level above it, do you??You might also try the following from a terminal:
find / -name boost -type d -print
Does it only report one directory named
boost
? Just in/usr/include
, nowhere else, right?Last thing: you might try setting up a brand new project in a brand new directory as a Qt project. Add only the
file.cpp
containing just the#include
line. Try to compile. Success or failure? -
-
@A123 said in Adding Boost to Creator:
All 4 generate file.o
OK. Not sure that was the impression I got previously, but I get it now. That ought to be a good start!
So I think the problem is some setting within QT creator itself.
Creator does not do compiling itself. It is an IDE which calls on external tools (e.g.
g++
) to do compilations.Let's start by being 100.000% clear. Your screenshot shows errors. Do you indeed get these when you COMPILE ? If you only get these when looking at your source code in the IDE, not when you actually compile, now is the time to say so! That would be a totally different situation.... So please make this crystal clear?
Assuming you get them when you allow Creator to invoke the compiler. Then in principle there are really/mostly only two things in Creator which affect this:
-
Show the actual command-line being issued to compile the file. You can find this in Creator on the Compiler Output pane.
-
There is a Build Environment setting. That allows environment variables to be passed to the compiler which we do not see on its command-line. Do you have anything of interest there?
You could show these two.
One other random thought: you do not have a sub-directory named
boost
in, say, your source directory, or perhaps one level above it, do you??You might also try the following from a terminal:
find / -name boost -type d -print
Does it only report one directory named
boost
? Just in/usr/include
, nowhere else, right?Last thing: you might try setting up a brand new project in a brand new directory as a Qt project. Add only the
file.cpp
containing just the#include
line. Try to compile. Success or failure?Let's start by being 100.000% clear. Your screenshot shows errors. Do you indeed get these when you COMPILE ? If you only get these when looking at your source code in the IDE, not when you actually compile, now is the time to say so! That would be a totally different situation.... So please make this crystal clear?
The line is labeled with a 'no such file or directory' error as soon as I paste it into the Creator code edit window. It pops up again in compile output when I attempt to build the project.
Assuming you get them when you allow Creator to invoke the compiler. Then in principle there are really/mostly only two things in Creator which affect this:
I put an empty file with the include in a sample project.
15:02:39: Running steps for project sampleproj2... 15:02:39: Starting: "/app/bin/qmake" /home/samp/sampleproj2/sampleproj2.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug 15:02:39: The process "/app/bin/qmake" exited normally. 15:02:39: Starting: "/usr/bin/make" -f /home/samp/build-sampleproj2-Qt6-Debug/Makefile qmake_all make: Nothing to be done for 'qmake_all'. 15:02:39: The process "/usr/bin/make" exited normally. 15:02:39: Starting: "/usr/bin/make" -j16 g++ -c -pipe -g -std=gnu++1z -Wall -Wextra -fPIC -DQT_QML_DEBUG -I../sampleproj2 -I. -I/app/mkspecs/linux-g++ -o file.o ../sampleproj2/file.cpp ../sampleproj2/file.cpp:1:10: fatal error: boost/algorithm/string.hpp: No such file or directory 1 | #include <boost/algorithm/string.hpp> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. make: *** [Makefile:875: file.o] Error 1 15:02:39: The process "/usr/bin/make" exited with code 2. Error while building/deploying project sampleproj2 (kit: Qt6) When executing step "Make" 15:02:39: Elapsed time: 00:00.
There is a Build Environment setting. That allows environment variables to be passed to the compiler which we do not see on its command-line. Do you have anything of interest there?
One other random thought: you do not have a sub-directory named boost in, say, your source directory, or perhaps one level above it, do you??
nope
Does it only report one directory named boost? Just in /usr/include, nowhere else, right?
sudo find / -name boost -type d -print find: ‘/run/user/1000/doc’: Permission denied find: ‘/run/user/1000/gvfs’: Permission denied /usr/lib/python3/dist-packages/boost /usr/lib/llvm-14/include/clang-tidy/boost /usr/include/boost /usr/include/boost/hana/ext/boost /usr/include/boost/chrono/typeof/boost
Last thing: you might try setting up a brand new project in a brand new directory as a Qt project. Add only the file.cpp containing just the #include line. Try to compile. Success or failure?
Failure as shown above.
-
-
Let's start by being 100.000% clear. Your screenshot shows errors. Do you indeed get these when you COMPILE ? If you only get these when looking at your source code in the IDE, not when you actually compile, now is the time to say so! That would be a totally different situation.... So please make this crystal clear?
The line is labeled with a 'no such file or directory' error as soon as I paste it into the Creator code edit window. It pops up again in compile output when I attempt to build the project.
Assuming you get them when you allow Creator to invoke the compiler. Then in principle there are really/mostly only two things in Creator which affect this:
I put an empty file with the include in a sample project.
15:02:39: Running steps for project sampleproj2... 15:02:39: Starting: "/app/bin/qmake" /home/samp/sampleproj2/sampleproj2.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug 15:02:39: The process "/app/bin/qmake" exited normally. 15:02:39: Starting: "/usr/bin/make" -f /home/samp/build-sampleproj2-Qt6-Debug/Makefile qmake_all make: Nothing to be done for 'qmake_all'. 15:02:39: The process "/usr/bin/make" exited normally. 15:02:39: Starting: "/usr/bin/make" -j16 g++ -c -pipe -g -std=gnu++1z -Wall -Wextra -fPIC -DQT_QML_DEBUG -I../sampleproj2 -I. -I/app/mkspecs/linux-g++ -o file.o ../sampleproj2/file.cpp ../sampleproj2/file.cpp:1:10: fatal error: boost/algorithm/string.hpp: No such file or directory 1 | #include <boost/algorithm/string.hpp> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. make: *** [Makefile:875: file.o] Error 1 15:02:39: The process "/usr/bin/make" exited with code 2. Error while building/deploying project sampleproj2 (kit: Qt6) When executing step "Make" 15:02:39: Elapsed time: 00:00.
There is a Build Environment setting. That allows environment variables to be passed to the compiler which we do not see on its command-line. Do you have anything of interest there?
One other random thought: you do not have a sub-directory named boost in, say, your source directory, or perhaps one level above it, do you??
nope
Does it only report one directory named boost? Just in /usr/include, nowhere else, right?
sudo find / -name boost -type d -print find: ‘/run/user/1000/doc’: Permission denied find: ‘/run/user/1000/gvfs’: Permission denied /usr/lib/python3/dist-packages/boost /usr/lib/llvm-14/include/clang-tidy/boost /usr/include/boost /usr/include/boost/hana/ext/boost /usr/include/boost/chrono/typeof/boost
Last thing: you might try setting up a brand new project in a brand new directory as a Qt project. Add only the file.cpp containing just the #include line. Try to compile. Success or failure?
Failure as shown above.
@A123
You have answered all my questions, but I'm sorry I just cannot spot what is wrong. You have shown:- The file
/usr/include/boost/algorithm/string.hpp
really does exist. - Sample programs with
#include <boost/algorithm/string.hpp>
compiled outside of Qt Creator work fine. - Programs, including a standalone one-liner project, with that line compiled inside Creator complain "no such file".
- From Creator I cannot see anything significant in the command-line or the environment passed to
g++
which would change the include search path behaviour.
You might just verify one thing. So far you have used
#include <boost/algorithm/string.hpp>
which ought find/usr/include/boost/algorithm/string.hpp
. Go look just in directory/usr/include/boost/
and pick some other.hpp
or.h
file which lives at that level. I don't know what is there. Say there is aboostfile.hpp
. Then try#include <boost/boostfile.hpp>
. I presume that fails equally? Otherwise if that succeeds there is something about the particularstring.hpp
file/path.Whatever the issue it should be something really simple! If I had your machine in front of me I would be confident of diagnosing whatever it is. But as it stands I am out of ideas. You will need someone else to look through with a fresh pair of eyes to see if they can spot what it might be.
- The file
-
@A123
You have answered all my questions, but I'm sorry I just cannot spot what is wrong. You have shown:- The file
/usr/include/boost/algorithm/string.hpp
really does exist. - Sample programs with
#include <boost/algorithm/string.hpp>
compiled outside of Qt Creator work fine. - Programs, including a standalone one-liner project, with that line compiled inside Creator complain "no such file".
- From Creator I cannot see anything significant in the command-line or the environment passed to
g++
which would change the include search path behaviour.
You might just verify one thing. So far you have used
#include <boost/algorithm/string.hpp>
which ought find/usr/include/boost/algorithm/string.hpp
. Go look just in directory/usr/include/boost/
and pick some other.hpp
or.h
file which lives at that level. I don't know what is there. Say there is aboostfile.hpp
. Then try#include <boost/boostfile.hpp>
. I presume that fails equally? Otherwise if that succeeds there is something about the particularstring.hpp
file/path.Whatever the issue it should be something really simple! If I had your machine in front of me I would be confident of diagnosing whatever it is. But as it stands I am out of ideas. You will need someone else to look through with a fresh pair of eyes to see if they can spot what it might be.
- The file