Sign in to follow this  
x_gamer_x

#pragma comment troubles

Recommended Posts

I'm having a problem with linking some libraries using #pragma comment(lib,"") This works fine if my library is in my main project directory:
#pragma comment(lib,"luad.lib")
But if I create a new folder called lua in my project folder and try:
#pragma comment(lib,"lua\\luad.lib")
I get the LINK error "cannot open luad.lib". I tried an absolute path as well ie "C:\\my solution\\my project\\luad.lib" which also did not work.

Share this post


Link to post
Share on other sites
Try using forward slashes. dunno if that will really help or not but I've never had a problem with pragmas... also you can try adding the library path to visual studios paths.

the Studio paths are in Tools->Options->Projects->VC++ Directories

Share this post


Link to post
Share on other sites
Thats what I am trying to avoid, is having to manually add the library via the IDE options.

I *could* put all the external libraries I am using in the main project folder, but that just seems like a mess, especially if you have a large project.

Can't figure out why this doesn't work. Ugh.

Share this post


Link to post
Share on other sites
You only need a single backslash in preprocessor directives liek #pragma. Alternatively, use forward slashes. They'll work on UNIX systems too, and will prevent this sort of thing from popping up

Share this post


Link to post
Share on other sites
Quote:
Original post by x_gamer_x
Thats what I am trying to avoid, is having to manually add the library via the IDE options.

The previous suggestion wasn't to add the specific library to the project. It meant to add the path to the IDE so that you could #pragma your lib in the code without the path. But then, is there any specific reason you want to avoid changing your project settings?

Share this post


Link to post
Share on other sites
The reason I am doing it this way is so that when I hand off my project to other teammembers and instructors they can open up the solution and compile right off the bat, without having to do the whole tools->options->projects deal for libraries I am using. Convience really.

Share this post


Link to post
Share on other sites
Quote:
Original post by x_gamer_x
The reason I am doing it this way is so that when I hand off my project to other teammembers and instructors they can open up the solution and compile right off the bat, without having to do the whole tools->options->projects deal for libraries I am using. Convience really.


Using pragma tells the project to include the library, but it doesn't tell it where to look. That still needs to be set up in your build environment (in your case the IDE).

Share this post


Link to post
Share on other sites
Quote:
Original post by petewood
Quote:
Original post by x_gamer_x
The reason I am doing it this way is so that when I hand off my project to other teammembers and instructors they can open up the solution and compile right off the bat, without having to do the whole tools->options->projects deal for libraries I am using. Convience really.


Using pragma tells the project to include the library, but it doesn't tell it where to look. That still needs to be set up in your build environment (in your case the IDE).

Yep, sounds like you might need to rethink your logistics a bit. If you are working on a project in a group there's a good chance the other teammembers should be building against the same environment, so that's really a non-issue.
Handing it in as an assignment is another matter though, and one which pretty much limits you to keeping all the headers and libs somewhere within your project directory. (As an instructor, I would expect zero installs or configuration to build a student project, lest the grade suffers.) Although, if you're using Visual Studio you can set additional lib and include directories in the actual project settings instead of the IDE, which is probably your best option for portability.

Share this post


Link to post
Share on other sites
If you don't want to use the project settings because you're worried about other people on the team not being able to compile the code because it is in a different directory (say, D:\Code\SomeDir\ where yours is in C:\Documents and Settings\%username%\My Projects\SomeDir\) you should be able to use '.' and '..' for paths in the Project settings and get a path relative to wherever the .vcproj/.dsp file is located

-nohbdy

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