Web Hosting Talk







View Full Version : c++ compiling help please


ilyash
05-13-2008, 01:12 PM
I'm trying to compile a c++ script i wrote under a linux environment (using gcc)

The problem is that there are a bunch of header files it can't find

The header files are not in the same directory as the script i wrote, so how do i tell the compiler to look in certain directories?

Thanks


also will gcc recognize that it is c++ or i need to tell it that also somehow?

debiannerd
05-13-2008, 02:17 PM
I'm trying to compile a c++ script i wrote under a linux environment (using gcc)

The problem is that there are a bunch of header files it can't find

The header files are not in the same directory as the script i wrote, so how do i tell the compiler to look in certain directories?

Thanks


also will gcc recognize that it is c++ or i need to tell it that also somehow?

gcc? you better off using g++

As for headers, you referring to libraries, you shouldn't need to point them to.

ilyash
05-13-2008, 02:26 PM
ok so when I do g++ filename.cpp

I get

stdafx.h: no such file or directory
and a bunch of others which are part of what i include

how do i specify for g++ to look for them in a certain place?

debiannerd
05-13-2008, 02:36 PM
ok so when I do g++ filename.cpp

I get

stdafx.h: no such file or directory
and a bunch of others which are part of what i include

how do i specify for g++ to look for them in a certain place?

stdafx.h ? that's a header that is "proper" to Visual C++

you don't need it, just delete it.

ilyash
05-13-2008, 04:22 PM
ok, but there are other files i include in my code and they are located in other directories

how do i tell g++ to look for those files in a specific place?

thanks

natsh
05-13-2008, 04:50 PM
you may want to do (as far as i know from C++)...

#include <filename.extension>

ilyash
05-13-2008, 06:03 PM
I do #include file.h

the problem is file.h is in a different dir so the compiler doesn't see it.

how do i tell the compiler to look in a different dir for that file

stdunbar
05-13-2008, 07:00 PM
With the -I command line option:


g++ -I/usr/local/dirname filename.cpp


That is a capital "i" as the command line option - depending on your display font it can be hard to read.

sasha
05-13-2008, 11:14 PM
... just to add, you can have multiple include paths, so this is valid
g++ -I/usr/include -I./include -I../include

-I. stands for current directory, -I../include for include directory just above your current directory and -I./include stands for include directory inside your current directory.