C++ #include library

Author
Discussion

aclivity

Original Poster:

4,072 posts

194 months

Monday 20th March 2023
quotequote all
I am trying to help my lad doing some work on a C++ code that needs to use an include library; all very simple however the library he wants to use requires some work to be done before he uses it?

I am in no way a C++ cider, however I have worked out that it is the "Boost" library, "Thread" code. This bit of code is not a headers only bit of code (?)

Last night he was getting angry at the world so in the end I had to take the laptop away from him, please can anyone tell me - in idiots terms (for me!) How to do the install of the code?

Andy

trashbat

6,008 posts

159 months

Monday 20th March 2023
quotequote all
It's been a long time since I wrote any C, so I can't necessarily help directly, but can you provide some more detail? What's the code you've written, what have you tried, what error are you getting? The more info the better.

jesusbuiltmycar

4,620 posts

260 months

Monday 20th March 2023
quotequote all
How is he building the code? Using the boost libraries is easier if using a package manager like CONAN, possibly combined with CMake.

Is the program something he has downloaded (if so it should have build/make files) or something he is writing from scratch?

If he is writing it from scratch he should be able to swa out boost::thread for std::thread


aclivity

Original Poster:

4,072 posts

194 months

Monday 20th March 2023
quotequote all
Sorry - got some more details now.

He is running it in visual studio 2022

The code is Boost - from wee.boost.org

I believe it is version 1.81.0 but not sure where he got it from? Or it could be the top link on boost.org to be honest!

He has created a library on documents\VisualStudio Libraries\boost_1_81_00 which has a lot of subfiles under it.

In the code, first line is #include<iostream> which appears to work fine,

Second line is #include<boost/thread.hpp> which I think where it fails?

Error message is this:

LNK1104 cannot open file 'libbost_thread-vc143-mt-gd-x64-1_81.lib

I have placed the directory into the path folder on projects, not sure what else to do?

aclivity

Original Poster:

4,072 posts

194 months

Monday 20th March 2023
quotequote all
Sorry - got some more details now.

He is running it in visual studio 2022

The code is Boost - from wee.boost.org

I believe it is version 1.81.0 but not sure where he got it from? Or it could be the top link on boost.org to be honest!

He has created a library on documents\VisualStudio Libraries\boost_1_81_00 which has a lot of subfiles under it.

In the code, first line is #include<iostream> which appears to work fine,

Second line is #include<boost/thread.hpp> which I think where it fails?

Error message is this:

LNK1104 cannot open file 'libbost_thread-vc143-mt-gd-x64-1_81.lib

I have placed the directory into the path folder on projects, not sure what else to do?

trashbat

6,008 posts

159 months

Monday 20th March 2023
quotequote all
That's good info.

The first answer (below the question) on this looks worth a try, making some substitutions for the version and locations you're using.

https://stackoverflow.com/questions/13042561/fatal...

Hanslow

809 posts

251 months

Monday 20th March 2023
quotequote all
The linker needs to know where to pick up the associated library. I'm guessing it can't get by with just a header usage of boost if it's wanting to pull in the lib folder. Find where he's picking up the boost/thread.hpp file from, that should get you into the location where the boost package is. Somewhere in there will be a lib folder that contains all the .lib files and he should be able to then find what he needs.

Bear in mind that boost is clever and will look for a version that matches the version of the compiler you are using, so it may be that you don't have a vc143 lib version available and may need to build the boost libs yourself with the version of Visual Studio being used, or find a distributable that includes it.

Once you've got the actual lib available, either prebuilt or built by yourselves, the path to the lib directory will need adding to the linker environment in the project solution properties.

aclivity

Original Poster:

4,072 posts

194 months

Monday 20th March 2023
quotequote all
trashbat said:
That's good info.

The first answer (below the question) on this looks worth a try, making some substitutions for the version and locations you're using.

https://stackoverflow.com/questions/13042561/fatal...
I passed this on to him, and it now works! Thanks very much for posting it, I tell him (over and over) that people on the internet may know what he is trying to do but he refuses to ask!

Of course I did take the Mickey a little bit first, which may not have helped!

Thanks again though, I have a happy son again now!

trashbat

6,008 posts

159 months

Monday 20th March 2023
quotequote all
aclivity said:
I passed this on to him, and it now works! Thanks very much for posting it, I tell him (over and over) that people on the internet may know what he is trying to do but he refuses to ask!

Of course I did take the Mickey a little bit first, which may not have helped!

Thanks again though, I have a happy son again now!
You're both welcome!

I'm a professional software engineer - not C/C++ these days though - and a key skill is, simple as it sounds, identifying the most relevant, searchable part of your problem, Googling it, and then identifying the relevant answers.

In your case, "LNK1104 cannot open file libbost_thread" turns up what I gave you.

It's obviously not the only part of the job by any means but a lot of problem solving ends up being stuff like this - especially project foundations or integrating existing things. Modern dev is complex enough such that nobody just knows all of this stuff.