0
votes

This static C library (libabc.a) is linked to a C++ program.

In my pro file for qmake, I have used
LIBS += pathToLib/libabc.a I had no problems when I created the static library. When using qmake and gmake to compile and run the cpp application, the object files for other cpp files are created but I get the following error:

../abc/libabc.a(mdl.o): In function 'SetExt': abc/src/mdl.c:2186: undefined reference to 'func1'

In mdl.c, both declaration and definition is there.
static void func1(int *, char *, char *);

static void func1(int *m, char *p, char *s)
{
.....
}

The function call of this function is in the C file mdl.c. Have I made a mistake when creating the static library (using gcc and ar)? or, what am I missing out?

1
@Incomputable not seeing an extern doesn't make it not both. It means that the linker's going to get confused later. I'm not the one you should be telling that to though - UKMonkey
@UKMonkey, thanks for the info. Is there any resource to read up about it? - Incomputable

1 Answers

1
votes

You declared your function as

static void func1(int *, char *, char *);

Per 6.2.2 Linkages of identifiers, paragraph 3 of the C Standard:

If the declaration of a file scope identifier for an object or a function contains the storage-class specifier static, the identifier has internal linkage.

Thus, func1() isn't accessible from outside of the compilation unit - it can only be used in the source file it's in.