News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Add existing file to a project

Started by erotavlas, November 17, 2010, 03:14:41 PM

Previous topic - Next topic

erotavlas

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

oBFusCATed

(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

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

xunxun

right-click project name -- Add files -- select file.h and click OK
Regards,
xunxun

Jenna

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

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.

MortenMacFly

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).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

erotavlas

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?

xunxun

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.
Regards,
xunxun

oBFusCATed

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

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.

xunxun

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

Jenna

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.

erotavlas

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

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?
Regards,
xunxun