Hi,
I'm new of Code::Block. I don't know how I can add an existing file to a project. If I add a file to a project clicking on project->add file recursively, Code::Block will add the file to my project. When I try to compile the project I get error from compiler, it can't find the added file from #include in other file.
data/myaddedfile.h
myfile.h (#include "myaddedfile.h")
main.cpp
I don't know why?
Thank
Read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
Quote from: oBFusCATed on November 17, 2010, 03:42:38 PM
Read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
Ok, thank you very much for your fast answer. I have read it and I know with other IDE how I can add a my existing file. I don't understand why Code::block can't allow to add an existing file in simple way.
I'm still getting this error:
file.h: No such file or directory
right-click project name -- Add files -- select file.h and click OK
It's a configuration error.
If the header file is not in the xsame directory as the c/cpp-file, you have to use the relative path in the include-statement or add the path to the compilers search directories in projects build options.
Quote from: xunxun1982 on November 17, 2010, 04:04:46 PM
right-click project name -- Add files -- select file.h and click OK
I'm sorry If my description is not good, but my problem is the following. I have a project with four file inside the my project folder:
main.cpp
file1.h
file1.cc
data/file2.h
file3.h
Inside of the file1.h there are the lines #include "data/file2.h", #include "file3.h". The compiler tells me: no such file data/file2.h and no such file file3.h.
I can't understand why, with other IDE is easier.
Quote from: erotavlas on November 17, 2010, 04:16:58 PM
I can't understand why, with other IDE is easier.
...because you forgot to add the path of your files to the compiler's include directories (thus telling the compiler where to look for include files). Just add "." (the dot).
Hi,
I have found the source of my problem. My description in the previous post was not completely correct...I'm sorry. If my project is like this:
main.cpp
file1.h
file1.cc
data/file2.h
file3.h
All works fine, but If my project is like this
main.cpp
file1.h
file1.cc
data/file2.h
data1/file4.h
file3.h
with #include "file4.h" inside the file file2.h, I get all the previous errors: no such file file4.h. So I can deduce that Code::block doesn't support multiple folders! Is it correct?Is there a workaround?
Quote from: erotavlas on November 17, 2010, 05:03:28 PM
Hi,
I have found the source of my problem. My description in the previous post was not completely correct...I'm sorry. If my project is like this:
main.cpp
file1.h
file1.cc
data/file2.h
file3.h
All works fine, but If my project is like this
main.cpp
file1.h
file1.cc
data/file2.h
data1/file4.h
file3.h
with #include "file4.h" inside the file file2.h, I get all the previous errors: no such file file4.h. So I can deduce that Code::block doesn't support multiple folders! Is it correct?Is there a workaround?
If you use #include "file4.h", you should add the "." and the "./data1" to the include path.
Most of the time "." should not be added (I think)...
The option is in Project -> Build options -> your target -> Search Paths -> Includes
Quote from: xunxun1982 on November 17, 2010, 05:11:45 PM
Quote from: erotavlas on November 17, 2010, 05:03:28 PM
Hi,
I have found the source of my problem. My description in the previous post was not completely correct...I'm sorry. If my project is like this:
main.cpp
file1.h
file1.cc
data/file2.h
file3.h
All works fine, but If my project is like this
main.cpp
file1.h
file1.cc
data/file2.h
data1/file4.h
file3.h
with #include "file4.h" inside the file file2.h, I get all the previous errors: no such file file4.h. So I can deduce that Code::block doesn't support multiple folders! Is it correct?Is there a workaround?
If you use #include "file4.h", you should add the "." and the "./data1" to the include path.
Yes, I have also tried it. The result is the same.
If you add include path, I have no idea.
I think you may try to change #include "file4.h" to #include "../data1/file4.h".
Quote from: erotavlas on November 17, 2010, 05:03:28 PM
So I can deduce that Code::block doesn't support multiple folders! Is it correct?
No, it's not correct.
C::B is an IDE not a compiler, and it's up to you to know how to set up your project correctly.
Thank you for your answer. I have not said that I'm under windows 7 with cygwin bash shell and g++/gcc 4.3.4 version1 compiler. I'm still trying to solve the problem, other suggestions are well accepted. Thank in advanced.
Quote from: erotavlas on November 18, 2010, 10:29:20 AM
Thank you for your answer. I have not said that I'm under windows 7 with cygwin bash shell and g++/gcc 4.3.4 version1 compiler. I'm still trying to solve the problem, other suggestions are well accepted. Thank in advanced.
I think cygwin gcc only recognize the path like "/cygdrive/", so if you use windows path, the gcc compiler may work wrongly.
Could you try to use mingw gcc?
Quote from: xunxun1982 on November 18, 2010, 10:51:45 AM
Quote from: erotavlas on November 18, 2010, 10:29:20 AM
Thank you for your answer. I have not said that I'm under windows 7 with cygwin bash shell and g++/gcc 4.3.4 version1 compiler. I'm still trying to solve the problem, other suggestions are well accepted. Thank in advanced.
I think cygwin gcc only recognize the path like "/cygdrive/", so if you use windows path, the gcc compiler may work wrongly.
Could you try to use mingw gcc?
The result with mingw is the same. Now I will try to put the project in c:\myproject. I hope that it works because it's the last my idea, could be windows (cygwin, minGW) the problem?
You're joking...
1. Have you tried to replace #include "file4.h" with #include "../data1/file4.h" or #include "data1/file4.h"?
2. Have you tried to add "./data1/" to the include paths?
If you have tried replace the "file4.h" with #include "../data1/file4.h", and you have added the include path, we felt very strange. If you have some web space such as Web Disk, you can upload the project to the space.
Quote from: oBFusCATed on November 18, 2010, 11:11:19 AM
You're joking...
1. Have you tried to replace #include "file4.h" with #include "../data1/file4.h" or #include "data1/file4.h"?
2. Have you tried to add "./data1/" to the include paths?
I have substituted all #include "file4.h" with #include "../data1/file4.h"
If I put all path "c:/myproject/data1/file4.h" it works perfectly. I can't understand why, but I'm very happy. :D