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

Offline 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.

data/myaddedfile.h
myfile.h (#include "myaddedfile.h")
main.cpp

I don't know why?

Thank

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12126
    • Travis build status
(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!]

Offline erotavlas

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

Offline 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

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
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.

Offline 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.

Offline MortenMacFly

  • Administrator
  • 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

Offline 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.cpp
file1.h
file1.cc
data/file2.h
file3.h
All works fine, but If my project is like this
Code: [Select]
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?

Offline 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.cpp
file1.h
file1.cc
data/file2.h
file3.h
All works fine, but If my project is like this
Code: [Select]
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.
Regards,
xunxun

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12126
    • Travis build status
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!]

Offline 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.cpp
file1.h
file1.cc
data/file2.h
file3.h
All works fine, but If my project is like this
Code: [Select]
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.

Offline 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

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
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.

Offline 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.

Offline 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