Function name scope in c

How does the function of determining the function name work in several C files?

I am migrating the standard gnu toolchain project to iPhone OS and use Xcode to do this.

The code builds through make, but not through xcode. when building through xcode, the linker complains that the same character (function) is defined in two objects. The code has two different source files, which #includeare a common file between them. Although ... weird (at least for me) seems to work for a standard toolchain. any ideas if this is something that is somehow handled differently via the standard makefile?

+3
source share
4 answers

Makefile, XCode, , , , - . Makefile, , 'gcc'. , , #ifdef, XCode.

+1

, , ( ). , , , .

.

, , . : common.h

int foo = 42;

:

extern int foo; // a declaration

common.c, :

int foo = 42;
+4

C, , static , , . , file1.c

void fn1() {}
static void fn2() {}

file2.c

void fn1() {}
static void fn2() {}

-

cc file1.c file2.c

fn1 file1.c fn1 file2.c, fn2 ( ). (, , , .)

+3

I assume that the generic header defines an inline function that results in duplicate characters. If so, prefix these functions with static inlineor define them as inlinewith a declaration externin another .c file.

+1
source

Source: https://habr.com/ru/post/1703718/


All Articles