I have a problem with Visual Studio 2012
I want to include one header file in other and then to include the second header file in .c file. I want to define a constant in first header file and use its value in c file. I think this is possible because it is done in standart libraries
When I do this compiler is sending an error message:
1>C:\\Users\\sotfware\\Desktop\\ConsoleApplication4\\Debug\\ConsoleApplication4.exe : fatal error LNK1169: one or more multiply defined symbols found
Put the definitions (body) of the functions in a regular C file and only the declarations in the header files. Let's say I have these functions:
void PrintHelloWorld(void)
{
printf("Hello World\n");
}
void PrintHelloWorld2(void)
{
printf("Hello World");
}
Then my C file would stay this ^^ but the Header file should be:
void PrintHelloWorld();
void PrintHelloWorld2();
As I remember, I think you should declare the constant in the header file.
I think it's OK. Maybe you can show more details about your problem.
First header (ah):
#ifndef A_H
#define A_H
const int i = 5;
#endif
Second header (bh):
#ifndef B_H
#define B_H
#include "a.h"
#endif
source file:
#include <stdio.h>
#include "b.h"
main() {
printf("%d\n", i);
exit(0);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.