### Author Topic: Add existing file to a project  (Read 37467 times)

#### erotavlas

• Multiple posting newcomer
• Posts: 19
##### Add existing file to a project
« 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.

main.cpp

I don't know why?

Thank

#### oBFusCATed

• Developer
• Lives here!
• Posts: 12126
##### Re: Add existing file to a project
« Reply #1 on: November 17, 2010, 03:42:38 pm »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

#### erotavlas

• Multiple posting newcomer
• Posts: 19
##### Re: Add existing file to a project
« Reply #2 on: November 17, 2010, 03:51:32 pm »

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

#### xunxun

• Almost regular
• Posts: 187
##### Re: Add existing file to a project
« Reply #3 on: November 17, 2010, 04:04:46 pm »
right-click project name -- Add files -- select file.h and click OK
Regards,
xunxun

#### jens

• Lives here!
• Posts: 7265
##### Re: Add existing file to a project
« Reply #4 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.

#### erotavlas

• Multiple posting newcomer
• Posts: 19
##### Re: Add existing file to a project
« Reply #5 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.

#### MortenMacFly

• Lives here!
• Posts: 9508
##### Re: Add existing file to a project
« Reply #6 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).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

#### erotavlas

• Multiple posting newcomer
• Posts: 19
##### Re: Add existing file to a project
« Reply #7 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: [Select]
`main.cppfile1.hfile1.ccdata/file2.hfile3.h`All works fine, but If my project is like this
Code: [Select]
`main.cppfile1.hfile1.ccdata/file2.hdata1/file4.hfile3.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?

#### xunxun

• Almost regular
• Posts: 187
##### Re: Add existing file to a project
« Reply #8 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: [Select]
`main.cppfile1.hfile1.ccdata/file2.hfile3.h`All works fine, but If my project is like this
Code: [Select]
`main.cppfile1.hfile1.ccdata/file2.hdata1/file4.hfile3.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.
Regards,
xunxun

#### oBFusCATed

• Developer
• Lives here!
• Posts: 12126
##### Re: Add existing file to a project
« Reply #9 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
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

#### erotavlas

• Multiple posting newcomer
• Posts: 19
##### Re: Add existing file to a project
« Reply #10 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: [Select]
`main.cppfile1.hfile1.ccdata/file2.hfile3.h`All works fine, but If my project is like this
Code: [Select]
`main.cppfile1.hfile1.ccdata/file2.hdata1/file4.hfile3.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.

#### xunxun

• Almost regular
• Posts: 187
##### Re: Add existing file to a project
« Reply #11 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".
Regards,
xunxun

#### jens

• Lives here!
• Posts: 7265
##### Re: Add existing file to a project
« Reply #12 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.

#### erotavlas

• Multiple posting newcomer
• Posts: 19
##### Re: Add existing file to a project
« Reply #13 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.

#### xunxun

• Almost regular
• Posts: 187
##### Re: Add existing file to a project
« Reply #14 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?
Regards,
xunxun

#### erotavlas

• Multiple posting newcomer
• Posts: 19
##### Re: Add existing file to a project
« Reply #15 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?

#### oBFusCATed

• Developer
• Lives here!
• Posts: 12126
##### Re: Add existing file to a project
« Reply #16 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?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

#### xunxun

• Almost regular
• Posts: 187
##### Re: Add existing file to a project
« Reply #17 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.
Regards,
xunxun

#### erotavlas

• Multiple posting newcomer
• Posts: 19
##### Re: Add existing file to a project
« Reply #18 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.