Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: erotavlas on November 17, 2010, 03:14:41 pm

Title: Add existing file to a project
Post by: erotavlas on November 17, 2010, 03:14:41 pm
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
Title: Re: Add existing file to a project
Post by: 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
Title: Re: Add existing file to a project
Post by: erotavlas on November 17, 2010, 03:51:32 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
Title: Re: Add existing file to a project
Post by: xunxun on November 17, 2010, 04:04:46 pm
right-click project name -- Add files -- select file.h and click OK
Title: Re: Add existing file to a project
Post by: Jenna on November 17, 2010, 04:09:31 pm
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.
Title: Re: Add existing file to a project
Post by: erotavlas on November 17, 2010, 04:16:58 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.
Title: Re: Add existing file to a project
Post by: MortenMacFly on November 17, 2010, 04:26:03 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).
Title: Re: Add existing file to a project
Post by: 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:
Code
main.cpp
file1.h
file1.cc
data/file2.h
file3.h
All works fine, but If my project is like this
Code
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?
Title: Re: Add existing file to a project
Post by: xunxun on November 17, 2010, 05:11:45 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:
Code
main.cpp
file1.h
file1.cc
data/file2.h
file3.h
All works fine, but If my project is like this
Code
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.
Title: Re: Add existing file to a project
Post by: oBFusCATed on November 17, 2010, 05:13:32 pm
Most of the time "." should not be added (I think)...

The option is in Project -> Build options -> your target -> Search Paths -> Includes
Title: Re: Add existing file to a project
Post by: erotavlas on November 17, 2010, 05:16:34 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:
Code
main.cpp
file1.h
file1.cc
data/file2.h
file3.h
All works fine, but If my project is like this
Code
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.
Title: Re: Add existing file to a project
Post by: xunxun on November 17, 2010, 05:29:30 pm
If you add include path, I have no idea.
I think you may try to change #include "file4.h" to #include "../data1/file4.h".
Title: Re: Add existing file to a project
Post by: Jenna on November 17, 2010, 07:43:10 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.
Title: Re: Add existing file to a project
Post by: 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.
Title: Re: Add existing file to a project
Post by: xunxun on November 18, 2010, 10:51:45 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?
Title: Re: Add existing file to a project
Post by: erotavlas on November 18, 2010, 11:04:07 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?
Title: Re: Add existing file to a project
Post by: 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?
Title: Re: Add existing file to a project
Post by: xunxun on November 18, 2010, 11:15:30 am
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.
Title: Re: Add existing file to a project
Post by: erotavlas on November 18, 2010, 11:31:25 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