Problem with adding new C file in project


Hi all.

I have a project in Eclipse. The version of OS is 4.24 (firmware is 663d for q2686). So when i try to add new C file in the project i recieve an error during compilation :frowning:

For example:

  1. I create the project based on Hello_World sample with use Open AT Project Wizard.
  2. The project by default contains a file hello_world.c.
  3. I create a new C file by open File-New-C Source File with new.c name.
  4. In hello_world.c file i insert include directive on my new.c file #include “new.c”.
  5. Then when i try to buid project i receive error: “new.c: No such file or directory”.
    —renaming new.c into new.h does not bring result: “new.h: No such file or directory”.
    —including this file manually in project settings by project - properties - include paths and symbols - add folder/file also does not bring result.

What do I do incorrectly? What correct algorithm?

Thanks a lot.


I’m guessing that you have two problems:
[]You didn’t specify, but I’m guessing that you saved new.c in the ‘src’ directory, where hello_world.c is. Since you are #including the file, you may need to move the file to the ‘itf’ directory.[/]
[]After adding any files to your project, you need to rerun the Project Wizard (or whatever it’s called) or run the wmnew command line tool.[/]


Thanks a lot for help.

Has understood. As a result it was necessary to move before compilation a new file in a folder inc. Further it is necessary to restart project wizard and go to Project - Clean. That is working.

Types.c about which I told this new name of a file earlier.


Why do you do that?

That’s a most unusual way to build a ‘C’ program! :open_mouth:


I really badly understand in programming on “C”, especially on eclipse platform (it’s new for me). The purpose was that: to allocate a part of code in other file for simplification of work with a code.


I suspected that might be the case.

In that case, you would probably find it a lot easier to learn ‘C’ programming on a “normal” platform like a PC before moving on to the added complications of embedded programming in general and Open-AT in particular.
There are plenty of books and courses available…

It’s basic ‘C’ stuff - nothing to do with any particular tool set.

A decent textbook and/or ‘C’ programming course will show you how to do this…


It’s basic ‘C’ stuff - nothing to do with any particular tool set.

Yes, you are rigth. But i think that my experience of development for PC will allow quickly to start to development applications for OEM wavecom devices.
I do not see a basic difference for itself. And about the books. I have bought couple of books about ‘C’ :unamused: Now I read Stepen Kochan ‘Programming in C’. Good texture. Who can that tell?


Hello all again.

The problem with code splitting is solved. Was to read a few books under the programming language enough :unamused:

But now I have faced other problem. Certainly the moderator can scold me for offtopic message but not to produce new themes, I will write here.

How to initialize a variable during its declaration in a header file?
Here an example from “QueryApp” by Wavecom (…from xxxxx.h file):

/* Boolean Variable which indicates if the Location information retrieved by the 
   CGPS library is valid or not */
bool LocValid = FALSE;

/* Variable which saves the last state of the LED (ON/OFF) */
u8 led=0;

And its from my header file:

bool        DebugInfoView = FALSE;

Thus compilation comes to an end with an error:
c:\OpenAT\IDE\MINGW\\bin\make.exe: *** [make_single_bin] Error 1

It is necessary to change the line to:

bool        DebugInfoView;

And this case all works well.

What am I do incorrectly? What i have to do to initialise this variable?


In a C file (xxxx.c), put:

bool        DebugInfoView = FALSE;

and in the header file (xxxx.h) put:

extern bool        DebugInfoView;

‘extern’ tells the compiler that the variable is declared in another file, which gets resolved by the linker at the end. The way you were doing it, you were trying to create a new DebugInfoView variable for each C file that included it (which causes problems once the linker tries to merge the object files into one binary).


You need to spend a little longer studying those ‘C’ textbooks!

In particular, you need to understand the difference between a declaration and a definition:

  • Every symbol must have exactly one definition within the program;

  • A symbol may have many declarations within the program.



Thanks indeed for help. Of course, this path will be the most correct. This i understood.
I do not understand how does an example of Wavecom? There is no declaration external variable and initialized in the header file. :question:


I am learning all the time. Almost constantly :confused:
Perhaps my English gives ambiguous concept of my thoughts, but i very much hope that those who read this - can understand that i would like to convey to them.

Yes, now i saw my error. Agree with you. Proposal

should write in another form: How to initialize a variable during its definition in a header file?


As long as the header file is included only once, then they can get away with sloppy code.


Please read that FAQ again:

You should not be placing a definition in a header file!

  • Keep your definitions (and, therefore, initialisations) in .c files only;
  • Have only declarations in your .h files

That way, you can’t go wrong.

Yes, there are cunning prepreocessor tricks that you can play to create a “dual-purpose” header - but you really needs to understand the basics first.

Anyhow, as the FAQ says,