How can I build a cpp file not in a project?

J

jr

I'm working with VC++ 7, but I think this rather dumb question is C++
related rather than Vis Studio related.

If this is the wrong place - apologies, just ignore it!


I am trying to use log4cpp, and I downloaded the zip files. When I wish to
use it in my code I can #include the required header file. However, when I
build I get link problems. This is because the cpp files are not being found
or compiled. I can tell VS to look in the correct folder for the cpp, but
that's not enough (C++ Directories).
Am I missing something here? I don't see why I should expect the compiler to
compile these library files but I do. Should I compile them as a separate
project do you think? I must say that I don't understand pre-compiled
headers either - is this something I should be looking at!

I know this is Vis Studio biased, but the problem is that there's a general
principle I don't understand.
Can you help?
Please excuse the extreme stupidity of this post.

Thanks very much.

john
 
A

Andrew Brampton

The quick fix for this is just create a new folder in your project's
"solution explorer" (that thing down the right) called log4cpp and put all
the c/cpp files into that. Then visual studio will know they need to be
compiled.
If you want you can make another project which just compiles this files.
Then add this project to your current solution and set your first project to
depend on the log4cpp project, and as such they will be compiled when/if
needed.

If the files aren't listed in your solution explorer they won't be compiled
or linked in. You can hope VC will compile them, but to be honest it doesn't
know which it should if any. The header files you are importing don't say
anything about where the actual code is, but when you add them to the
solution explorer it compiles them, and then later sees the compiled code
with the create function names at the linking stage.

Hope thats helpful?
Andrew

| I'm working with VC++ 7, but I think this rather dumb question is C++
| related rather than Vis Studio related.
|
| If this is the wrong place - apologies, just ignore it!
|
|
| I am trying to use log4cpp, and I downloaded the zip files. When I wish to
| use it in my code I can #include the required header file. However, when I
| build I get link problems. This is because the cpp files are not being
found
| or compiled. I can tell VS to look in the correct folder for the cpp, but
| that's not enough (C++ Directories).
| Am I missing something here? I don't see why I should expect the compiler
to
| compile these library files but I do. Should I compile them as a separate
| project do you think? I must say that I don't understand pre-compiled
| headers either - is this something I should be looking at!
|
| I know this is Vis Studio biased, but the problem is that there's a
general
| principle I don't understand.
| Can you help?
| Please excuse the extreme stupidity of this post.
|
| Thanks very much.
|
| john
|
| --
| ---
| If you need to reply personally, append "text" to the domain name in my
| email adr.
| Thanks
|
|
 
J

John Harrison

jr said:
I'm working with VC++ 7, but I think this rather dumb question is C++
related rather than Vis Studio related.

If this is the wrong place - apologies, just ignore it!

It is the wrong place.
I am trying to use log4cpp, and I downloaded the zip files. When I wish to
use it in my code I can #include the required header file. However, when I
build I get link problems. This is because the cpp files are not being found
or compiled. I can tell VS to look in the correct folder for the cpp, but
that's not enough (C++ Directories).
Am I missing something here?

Yes, add the files to your project. Menu item File/Add Existing Item...

I don't see why I should expect the compiler to
compile these library files but I do. Should I compile them as a separate
project do you think? I must say that I don't understand pre-compiled
headers either - is this something I should be looking at!

No, its got nothing to do with it.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top