Problem with adding new C file in project


#1

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.


#2

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.[/]


#3

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.


#4

Why do you do that?

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


#5

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.


#6

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…


#7

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?


#8

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\3.8.0.1\bin\make.exe: *** [make_single_bin] Error 1
Done.

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?


#9

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


#10

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.

See: c-faq.com/decl/decldef.html


#11

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:


#12

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?


#13

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


#14

Please read that FAQ again: c-faq.com/decl/decldef.html

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,