How to add .c and .h files to Atmel Studio 6?

前端 未结 2 1463
梦毁少年i
梦毁少年i 2021-01-03 08:10

I know there are a lot of questions on this topic, and I\'ve looked through a fair number of them. However I am still having problems.

I started writing a test prog

相关标签:
2条回答
  • 2021-01-03 08:59

    Adding library files to a solution should be simple. Go to the Solution Explorer, right-click on your solution, and go to "Add->Existing Item". If you want to add a pre-existing library and keep it in a separate folder from your solution, click the arrow next to "Add" and choose "Add as link". That saves many headaches due to having a duplicate copy of your library in your solution folder, and files not staying up-to-date.

    0 讨论(0)
  • 2021-01-03 09:06

    You are right in saying that you need to include the necessary header files in the .c files where they are used.

    The compiler compiles each C file separately, and then links them together at the end, so you got the error unknown typename int_* because the compiler had not seen the relevant header in the context of compiling that C file.

    You also seem to be in some confusion as to the difference between definition and declaration.

    A function is:

    • Declared in the header file. This means there is a function prototype, e.g. int some_func(char some_var); which tells the compiler that the function exists, but does not tell it what it is. This is necessary because the compiler only looks at one C file at a time, so needs to be told that other functions exist.
    • Defined in the C file.This is the actual function body, i.e. int some_func(char some_var) { do_stuff(some_var); }. After compilation of each individual C file in isolation, the linker is called to put all the pieces together and give you your final binary, which you flash to the device.

    A function can be (and must be) defined only once, but may be declared many times - even in the same file, so long as the declarations are not conflicting.

    0 讨论(0)
提交回复
热议问题