LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   header files in c++ programming (https://www.linuxquestions.org/questions/linux-newbie-8/header-files-in-c-programming-4175414829/)

amitback 07-04-2012 04:50 AM

header files in c++ programming
 
hello frnds,
I have just installed BACKTRACK linux on my computer.
I use BACKTRACK for my c++ programming practice but my problem is I am not able to include the user created header files in my program.
Usually I create 2 header files one in which I declare the functions and other in which I define those. I save those files(filename.h ) in root folder.
and in .cpp file I use #include"filenamae.h" statement so that those files will be included in main()
but I am getting error "a3.cpp:2:14: error: filename: No such file or directory"
pls help!!

kauuttt 07-04-2012 04:55 AM

#include"filenamae.h"

Is it a typo? Or because of this you are seeing the issue? :)

-kd

pan64 07-04-2012 04:58 AM

what do you mean by root folder? Can you please show us a tree how your files are organized! Also how did you try to build your app? What was the command you executed? (I hope you do not use root user to do this)

amitback 07-04-2012 04:59 AM

Quote:

Originally Posted by kauuttt (Post 4718900)
#include"filenamae.h"

Is it a typo? Or because of this you are seeing the issue? :)

-kd

its certainly not a typo! :)

amitback 07-04-2012 05:06 AM

Quote:

Originally Posted by pan64 (Post 4718902)
what do you mean by root folder? Can you please show us a tree how your files are organized! Also how did you try to build your app? What was the command you executed? (I hope you do not use root user to do this)

root folder means when i open home folder from places i can view that file..
and I am logged in as root!! is there any problem bcoz i dnt have any imp data in my hdd

kauuttt 07-04-2012 05:09 AM

Quote:

Originally Posted by amitback (Post 4718903)
its certainly not a typo! :)

Didn't get your point clearly..

is the name of the file filenamae.h? and still you are not getting it while compiling?

In that case, can you please run "tree" and post it please..need to know the directory structure what you are using.

amitback 07-04-2012 05:12 AM

Quote:

Originally Posted by kauuttt (Post 4718911)
Didn't get your point clearly..

is the name of the file filenamae.h? and still you are not getting it while compiling?

In that case, can you please run "tree" and post it please..need to know the directory structure what you are using.

.
├── a1.cpp
├── a1.cpp~
├── a2.cpp
├── a2.cpp~
├── #a3.cpp#~
├── a3.cpp
├── a3.cpp~
├── amit
│** ├── Biomedical Instrumentation.pdf
│** ├── Civil IV.pdf
│** ├── Civil VIII.pdf
│** ├── Civil VI.pdf
│** ├── Comp IV.pdf
│** ├── Computer Engineering.pdf
│** ├── Comp VIII.pdf
│** ├── Comp VI.pdf
│** ├── Construction management.pdf
│** ├── Control Systems.pdf
│** ├── Design Engineering.pdf
│** ├── Digital Systems.pdf
│** ├── Elec IV.pdf
│** ├── Elec VI.pdf
│** ├── Environmental water resourses.pdf
│** ├── E&TC IV.pdf
│** ├── E&TC VIII.pdf
│** ├── E&TC VI.pdf
│** ├── Geotechnical Engineering.pdf
│** ├── Heat Power Engineering.pdf
│** ├── Instru IV.pdf
│** ├── Instru VIII.pdf
│** ├── Instru VI.pdf
│** ├── IT IV.pdf
│** ├── IT VIII.pdf
│** ├── IT VI.pdf
│** ├── Manufacturing Engineering and Automation.pdf
│** ├── Mechatronics.pdf
│** ├── Mech IV.pdf
│** ├── Mech VIII.pdf
│** ├── Mech VI.pdf
│** ├── Meta IV.pdf
│** ├── Meta VI.pdf
│** ├── Physical Metallurgy.pdf
│** ├── Power Systems.pdf
│** ├── Process Instrumentation.pdf
│** ├── Process Metallurgy.pdf
│** ├── prod IV.pdf
│** ├── prod VI.pdf
│** ├── Sem II Applied Science.pdf
│** ├── Signal Processing.pdf
│** ├── Structural engg.pdf
│** ├── Town and Country Planning.pdf
│** ├── VLSI and Embedded System.pdf
│** └── Wired & Wireless Communication.pdf
├── A.PRACTICAL.GUIDE.TO.UBUNTU.LINUX.3rd.EDITION.EBOOK.PAPU.pdf
├── bayago bayago.mp3
├── COEP_Registration_Process_June25_2012.pdf
├── dec.h
├── def.h
├── Desktop
│** ├── A.PRACTICAL.GUIDE.TO.UBUNTU.LINUX.3rd.EDITION.EBOOK.PAPU.pdf
│** ├── backtrack-install.desktop
│** ├── Let Us C - Yashwant Kanetkar.pdf
│** └── The Basics of Hacking and Penetration Testing Ethical Hacking and Penetration Testing Made Easy
│** ├── Openmirrors.com__The_Basics_of_Hacking_and_Penetration_Testing__Ethical_Hacking_and_Penetration_Test ing_Made_Easy.pdf
│** └── Torrent downloaded from Demonoid.me.txt
├── Downloads
│** └── Branch_Change_Notice.pdf
├── emma1.jpg
├── firefox
│** ├── application.ini
│** ├── blocklist.xml
│** ├── chrome
│** │** └── icons
│** │** └── default
│** │** ├── default16.png
│** │** ├── default32.png
│** │** └── default48.png
│** ├── chrome.manifest
│** ├── components
│** │** ├── binary.manifest
│** │** ├── libbrowsercomps.so
│** │** ├── libdbusservice.so
│** │** ├── libmozgnome.so
│** │** └── libnkgnomevfs.so
│** ├── crashreporter
│** ├── crashreporter.ini
│** ├── crashreporter-override.ini
│** ├── defaults
│** │** └── pref
│** │** └── channel-prefs.js
│** ├── dependentlibs.list
│** ├── dictionaries
│** │** ├── en-US.aff
│** │** └── en-US.dic
│** ├── extensions
│** │** └── {972ce4c6-7e08-4474-a285-3208198ce6fd}
│** │** ├── icon.png
│** │** ├── install.rdf
│** │** └── preview.png
│** ├── firefox
│** ├── firefox-bin
│** ├── icons
│** │** ├── mozicon128.png
│** │** └── updater.png
│** ├── jsloader
│** │** └── resource
│** ├── libfreebl3.chk
│** ├── libfreebl3.so
│** ├── libmozalloc.so
│** ├── libmozsqlite3.so
│** ├── libnspr4.so
│** ├── libnss3.so
│** ├── libnssckbi.so
│** ├── libnssdbm3.chk
│** ├── libnssdbm3.so
│** ├── libnssutil3.so
│** ├── libplc4.so
│** ├── libplds4.so
│** ├── libsmime3.so
│** ├── libsoftokn3.chk
│** ├── libsoftokn3.so
│** ├── libssl3.so
│** ├── libxpcom.so
│** ├── libxul.so
│** ├── mozilla-xremote-client
│** ├── omni.ja
│** ├── platform.ini
│** ├── plugin-container
│** ├── precomplete
│** ├── removed-files
│** ├── run-mozilla.sh
│** ├── searchplugins
│** │** ├── amazondotcom.xml
│** │** ├── bing.xml
│** │** ├── eBay.xml
│** │** ├── google.xml
│** │** ├── twitter.xml
│** │** ├── wikipedia.xml
│** │** └── yahoo.xml
│** ├── Throbber-small.gif
│** ├── updater
│** ├── updater.ini
│** └── update-settings.ini
├── linux command learning.pdf
└── qBT_dir
this is the tree ...
and the names of files are dec.h and def.h!! but how can name of file matter(if it is typed correctly in each step??

kauuttt 07-04-2012 05:21 AM

I hope the source files of yours are - a*.cpp.
If the src file and the .h files are there in the same directory, then a simple gcc a*.cpp should be enough!
Please cross check your header inclusion; presence of the files; makefiles (if any) to wipe out any probable human error..

amitback 07-04-2012 05:24 AM

Quote:

Originally Posted by kauuttt (Post 4718920)
I hope the source files of yours are - a*.cpp.
If the src file and the .h files are there in the same directory, then a simple gcc a*.cpp should be enough!
Please cross check your header inclusion; presence of the files; makefiles (if any) to wipe out any probable human error..

can u pls tell me what is use of "make file" statement I have read about it in many posts but I dont knw anything about it
how can I check whether they are in same directory or not?
you may seem questions very silly but i am complete newbie!!

anshuman84 07-04-2012 06:17 AM

Quote:

Originally Posted by amitback (Post 4718914)
.
├── a1.cpp
├── a1.cpp~
├── a2.cpp
├── a2.cpp~
├── #a3.cpp#~
├── a3.cpp
├── a3.cpp~
├── amit
│** ├── Biomedical Instrumentation.pdf
│** ├── Civil IV.pdf
│** ├── Civil VIII.pdf
│** ├── Civil VI.pdf
│** ├── Comp IV.pdf
│** ├── Computer Engineering.pdf
│** ├── Comp VIII.pdf
│** ├── Comp VI.pdf
│** ├── Construction management.pdf
│** ├── Control Systems.pdf
│** ├── Design Engineering.pdf
│** ├── Digital Systems.pdf
│** ├── Elec IV.pdf
│** ├── Elec VI.pdf
│** ├── Environmental water resourses.pdf
│** ├── E&TC IV.pdf
│** ├── E&TC VIII.pdf
│** ├── E&TC VI.pdf
│** ├── Geotechnical Engineering.pdf
│** ├── Heat Power Engineering.pdf
│** ├── Instru IV.pdf
│** ├── Instru VIII.pdf
│** ├── Instru VI.pdf
│** ├── IT IV.pdf
│** ├── IT VIII.pdf
│** ├── IT VI.pdf
│** ├── Manufacturing Engineering and Automation.pdf
│** ├── Mechatronics.pdf
│** ├── Mech IV.pdf
│** ├── Mech VIII.pdf
│** ├── Mech VI.pdf
│** ├── Meta IV.pdf
│** ├── Meta VI.pdf
│** ├── Physical Metallurgy.pdf
│** ├── Power Systems.pdf
│** ├── Process Instrumentation.pdf
│** ├── Process Metallurgy.pdf
│** ├── prod IV.pdf
│** ├── prod VI.pdf
│** ├── Sem II Applied Science.pdf
│** ├── Signal Processing.pdf
│** ├── Structural engg.pdf
│** ├── Town and Country Planning.pdf
│** ├── VLSI and Embedded System.pdf
│** └── Wired & Wireless Communication.pdf
├── A.PRACTICAL.GUIDE.TO.UBUNTU.LINUX.3rd.EDITION.EBOOK.PAPU.pdf
├── bayago bayago.mp3
├── COEP_Registration_Process_June25_2012.pdf
├── dec.h
├── def.h
├── Desktop
│** ├── A.PRACTICAL.GUIDE.TO.UBUNTU.LINUX.3rd.EDITION.EBOOK.PAPU.pdf
│** ├── backtrack-install.desktop
│** ├── Let Us C - Yashwant Kanetkar.pdf
│** └── The Basics of Hacking and Penetration Testing Ethical Hacking and Penetration Testing Made Easy
│** ├── Openmirrors.com__The_Basics_of_Hacking_and_Penetration_Testing__Ethical_Hacking_and_Penetration_Test ing_Made_Easy.pdf
│** └── Torrent downloaded from Demonoid.me.txt
├── Downloads
│** └── Branch_Change_Notice.pdf
├── emma1.jpg
├── firefox
│** ├── application.ini
│** ├── blocklist.xml
│** ├── chrome
│** │** └── icons
│** │** └── default
│** │** ├── default16.png
│** │** ├── default32.png
│** │** └── default48.png
│** ├── chrome.manifest
│** ├── components
│** │** ├── binary.manifest
│** │** ├── libbrowsercomps.so
│** │** ├── libdbusservice.so
│** │** ├── libmozgnome.so
│** │** └── libnkgnomevfs.so
│** ├── crashreporter
│** ├── crashreporter.ini
│** ├── crashreporter-override.ini
│** ├── defaults
│** │** └── pref
│** │** └── channel-prefs.js
│** ├── dependentlibs.list
│** ├── dictionaries
│** │** ├── en-US.aff
│** │** └── en-US.dic
│** ├── extensions
│** │** └── {972ce4c6-7e08-4474-a285-3208198ce6fd}
│** │** ├── icon.png
│** │** ├── install.rdf
│** │** └── preview.png
│** ├── firefox
│** ├── firefox-bin
│** ├── icons
│** │** ├── mozicon128.png
│** │** └── updater.png
│** ├── jsloader
│** │** └── resource
│** ├── libfreebl3.chk
│** ├── libfreebl3.so
│** ├── libmozalloc.so
│** ├── libmozsqlite3.so
│** ├── libnspr4.so
│** ├── libnss3.so
│** ├── libnssckbi.so
│** ├── libnssdbm3.chk
│** ├── libnssdbm3.so
│** ├── libnssutil3.so
│** ├── libplc4.so
│** ├── libplds4.so
│** ├── libsmime3.so
│** ├── libsoftokn3.chk
│** ├── libsoftokn3.so
│** ├── libssl3.so
│** ├── libxpcom.so
│** ├── libxul.so
│** ├── mozilla-xremote-client
│** ├── omni.ja
│** ├── platform.ini
│** ├── plugin-container
│** ├── precomplete
│** ├── removed-files
│** ├── run-mozilla.sh
│** ├── searchplugins
│** │** ├── amazondotcom.xml
│** │** ├── bing.xml
│** │** ├── eBay.xml
│** │** ├── google.xml
│** │** ├── twitter.xml
│** │** ├── wikipedia.xml
│** │** └── yahoo.xml
│** ├── Throbber-small.gif
│** ├── updater
│** ├── updater.ini
│** └── update-settings.ini
├── linux command learning.pdf
└── qBT_dir
this is the tree ...
and the names of files are dec.h and def.h!! but how can name of file matter(if it is typed correctly in each step??


Check the owner of your files. If the owner of your CPP file and .h file is different then may this problem will occur.
After changing the owner if still problem persists then in your CPP file include like this #include "fullpath to def.h"
This should solve your problem.

pan64 07-04-2012 07:02 AM

instead of #include "fullpath to file" use: #include "file.h" and gcc -I <path to file.h> ...

amitback 07-05-2012 12:33 AM

thanks frnds my issue is solved and now i can run my c++ program on linux very comfortably ...thank u so much for your help!!


All times are GMT -5. The time now is 12:30 PM.