473,394 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to set the include path an environment variables of g++

Hi:
Recently I was very interested in console model to compile some simple examples of c++, Unfortunately,I failed to do so.
My operation system is winxp, and I had installed DevCPP 4 inside. I also set path = "c:\dev-c++\bin", but it seemed to be hard to determine where and what I could set my "Include" and "lib".
For example:A simple piece of my code #include <iostream.h> doesn't work, the error raised by g++ is "can't find iostream.h"
PLS Help me ; a begginer of c++.
I've searched my question in this forum,but no suitble answer.Google don't work as well as your country in my homeland.
Sep 17 '07 #1
5 31819
RRick
463 Expert 256MB
In unix, the PATH variable is good for finding programs (like your compiler). For the include and lib paths, you have to tell the compiler directly. For includes, add a -I (big i) in front of each include directory. For libraries, the simpliest way is to add -l (small l) before the complete path and library name. For example:

g++ -I. -I../include -l../lib/libstuff.a ... blah blah blah ...

Its also smart to turn on the compiler warnings (-Wall) and the debugger (-g -O0). Try 'man g++' to get more options, but watch out, there are a lot of them.
Sep 18 '07 #2
RRick:
Thank for your reply. "g++ -i" really help.
For std lib, Is there easy way such as Java's lib and include to set the path?
Sep 18 '07 #3
RRick
463 Expert 256MB
For the C++ and system libraries, the compiler knows where they are and takes care of the include and library path information.

You only need to add include paths for header files that aren't the C++ header files. Some of the sytem libraries need to be explicitly defined. Some are:
  • -lm // math library
  • -lpthread // Thread library
Your own and 3rd party libraries are bit more involved and take a -L (big L) path parameter. All libraries have the form lib<name>.a for a static library. For -lm the compiler looks for libm.a.
Sep 18 '07 #4
In unix, the PATH variable is good for finding programs (like your compiler). For the include and lib paths, you have to tell the compiler directly. For includes, add a -I (big i) in front of each include directory. For libraries, the simpliest way is to add -l (small l) before the complete path and library name. For example:

g++ -I. -I../include -l../lib/libstuff.a ... blah blah blah ...

Its also smart to turn on the compiler warnings (-Wall) and the debugger (-g -O0). Try 'man g++' to get more options, but watch out, there are a lot of them.
How exactly do I go about doing that? I have the exact same problem as the guy who started this thread.
Sep 7 '08 #5
If you are using an IDE such as Dev-CPP, there shouldn't be any error finding standard headers when you include. If there is a search issue you can add the path in the compiler options within the IDE. Also, know that a modern IDE usually takes care of the cmpiler parameter business for you, so you only need to tell the IDE where to find your lib and include folders. In fact, the IDE makes a full make file for you with all necessary variables / compiler parameters! Also, check your syntax, for not all header files in the std library set requires .h. Example, #include <iostream.h> would in fact be #include <iostream>. I had Dev-CPP before Code::Blocks and I used to have that problem, since some headers do need the .h. Try my correction and report back! That should be my mole of Si (a chemist will get this)! :)
Sep 29 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Artco News | last post by:
How to get Windows XP Server(where PHP Server is running) environment variables? I use the echo $_ENV seem to not working. The same for any other environment variables. I'm running PHP-4.3.4...
1
by: darrel | last post by:
We've purchased a component that requires us to install two DLLs. One we add as a reference to our project, but the otherone we have to add to the 'environment setup' as a system path reference....
2
by: beaker | last post by:
Hi, This may be slightly OT, but as I'm using VB.NET I'll ask anyway... I'm trying to update my path using the following code to tweak the registry Dim regKey As RegistryKey regKey =...
10
by: mirandacascade | last post by:
O/S: Win2K Vsn of Python:2.4 Based on a search of other posts in this group, it appears as though os.environ is one way to obtain the PATH environment variable. My questions: 1) is it...
0
by: Andy Gimblett | last post by:
Hi all, Question: is there any way to use environment variables (or something similar) in my saved SQL code, and have them expanded at runtime? I can't see a way to do this in the manuals, and...
6
by: otto | last post by:
Hi, all: I would like to know one thing: Is it possible to access an environment variable (like PATH) from web.config file? Something like this: <appSettings> <add key="name"...
3
by: Tristan | last post by:
Hello community: I post this because I could not find satisfactory answers in the posts generated by this nice group. I work on winXP. I have many little python applications in different folders,...
2
by: dave6502 | last post by:
Struggling newbe here, some of my #includes work, some dont. Is it possible to list the include path ? (in BASH), I have looked at the environmental variables (loads of them) but cannot find a...
4
by: Krishna | last post by:
Environment variable set up is the most confusing part for me all the time. Please help me with the following questions: When I install python in a new system, I will go to environment variables...
3
by: smitty1e | last post by:
Just a fun exercise to unify some of the major input methods for a script into a single dictionary. Here is the output, given a gr.conf file in the same directory with the contents stated below: ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.