[SOlved] how to include files easily?
-
Hello,
after having learnt how to use extern c++ files in project ("here":http://qt-project.org/forums/viewthread/16719/) I want to know how to include the header file if it is not in the same directory.
I already tried adding the path with INCLUDEPATH like I did it before but for some reason I don't know it doesn't work.
When I am in the code editor I can go to the definition of a function with CTRL+mouseclick but the compiler said
mainwindow.cpp:111: error:undefined reference to `useful::power(double)'
Additionally, I want to include the header file by including a file with no extension which includes my header file and is called Useful.I hope it is not wrong to create a new topic because I want to know how to link to these files in other directories and not what should be in them itself.
Thank you
-
This is not a compile Error, it's a link Error which means that your header file has been found and your source code has been compiled successfully.
[quote author="pascal95abc" date="1335621385"]but the compiler said
mainwindow.cpp:111: error:undefined reference to `useful::power(double)'
[/quote] -
[quote author="pascal95abc" date="1335621385"]
Additionally, I want to include the header file by including a file with no extension which includes my header file and is called Useful.[/quote]
-
Change the name of you current header file to "Useful" directly.
-
Create a new file called "Useful", in which you include your old header file.
BTW, I don't think it is good idea to use header file without .h/.hpp extension for user defined header files.
-
-
I did not really get your explanations with creating the file Useful twice (?)
So, this is the way my folder structure looks like:
!http://o25.img-up.net/Screenshotnxk0.png(Projects/_useful/useful.h|useful.cpp|Useful)!If it is not possible to use Useful which includes useful.h then I will be ok with including useful.h directly.
-
Ah, My fault. ;-)
They are two methods, rather than two steps.
-
actually, method 2 is the one I am using right now AND does not work
I hope my picture made it clear how I want to have the structure. -
I really need this! I tried too much and nothing works!!!
How can I do this ?! why is it so complicated?! -
now this is solved
I have had a very simple idea:
#include actually just replaces the include command with the content of the specified file.
So I now have just a .cpp file with that simple content
@double sqr(douvle x){return x*x}@ and I include it.
So : no namespaces required ;)