Sign in to follow this  
JoeZ

lib and h in the project directory

Recommended Posts

JoeZ    139
Hi: I would like to know if I put the lib and h files in the same place as where I put my source files. How do I inlcude the lib without typing out the whole directory path? Thanks!

Share this post


Link to post
Share on other sites
Fruny    1658
Look up the -L and -I (or /L and /I) compiler and linker flags in your compiler documentation (L for library directories, I for include directories).

Share this post


Link to post
Share on other sites
JoeZ    139
Thanks!

I found out this way is easier
you can put the lib anywhere and include it

#pragma comment(lib, "name.lib")




Share this post


Link to post
Share on other sites
Drew_Benton    1861
Quote:
Original post by JoeZ
Thanks!

I found out this way is easier
you can put the lib anywhere and include it

#pragma comment(lib, "name.lib")


Just a note - I used to always suggest that for it works very well - until you are mixing libaries. If you are linking static libraries with dynamic, be warned that your program will not always compile right. I learned that the hard way with OpenAL and OGG Vorbis. Just a heads up.

Share this post


Link to post
Share on other sites
JoeZ    139
Hi Drew_Benton,

I agree that this method does create a lot of problems. I have to change the VC++ debug option to multi-threaded so the program can be built correctly. Looks like you have a lot of experiences. What would you suggest?

Thanks!

Share this post


Link to post
Share on other sites
Fruny    1658
Quote:
Original post by JoeZ
I have to change the VC++ debug option to multi-threaded so the program can be built correctly.


The C runtime you choose must match the one the other libraries you picked were compiled with. Hopefully, you'll be linking with libraries that all rely on the same runtime... otherwise, you're in trouble.

Quote:
you can put the lib anywhere and include it


Still has to be on your library search path. You can't go hide it in W:/Elder Gods/Cthulhu/phtagn/ and expect the linker to find it.

Share this post


Link to post
Share on other sites
Drew_Benton    1861
Quote:
Original post by JoeZ
I agree that this method does create a lot of problems. I have to change the VC++ debug option to multi-threaded so the program can be built correctly.


What exactly are you linking together, what libraries? I don't know if I've heard of them, but it's always useful information to everyone. When I tried mxing OGG static libraries with that od the dynamically linked OpenAL, I had to choose MT runtime as well. I guess as long as it compiles, you *should* be fine. I had no problems with mine, but I finally switched over to the non-static when I learend how to make them work (interal library problem, not mine).

Quote:
Looks like you have a lot of experiences. What would you suggest?


Well I don't have as much experience as Fruny does [grin], so make sure you listen to him too! He's taught me quite a lot [wink] and when you need help with the Standard C++ Library, he's your man.

When you use something like Dev-CPP, to link in libraries, you must use the methods that Fruny first posted. In Visual Studio, it takes care of all this for you [smile] - but you just have to make sure that the library can be found - aka it is in the current directory or it is in the 'lookup' directory. To add to this, you can go to Project->Properties->Linker then add the path in the "Additional Library Directories".

This way if you do move your .lib to somewhere like "W:/Elder Gods/Cthulhu/phtagn/" it will look there for your library [lol]. For header files the same can be done by going to the "C++"->"General" then the Additional Include Directories.

I think that's about it. However, in your original post, did you try linking in your libraries without setting the full path name? Earlier today I did a quick example with Allegro and I had copied the .lib/.h/.dll into where the .cpp files were and it compiled fine - I did not have them in my default vs lib folder.

Share this post


Link to post
Share on other sites
Fruny    1658
Quote:
Original post by Drew_Benton
To add to this, you can go to Project->Properties->Linker then add the path in the "Additional Library Directories".


Which boils down to adding a /L flag (look at what happens to the command line - I believe you get access to it under the "Advanced" tab). [wink]

Share this post


Link to post
Share on other sites
JoeZ    139
I am trying to link the lib3ds and OpenGL libraries.
I put the lib3ds.lib into a sub directory <lib> under my current project directory.
I used the whole path
#pragma comment(lib, "lib/lib3ds.lib")

Looks like it is working fine : )
Command-line is just too hard to work with
I am getting lazy. I like IDE more ;)

Thanks you guys!
I have learned a lot

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this