除了将hello()函数移动到另一个源(.cpp)文件或重命名该函数.有没有其他方法可以避免链接错误?
staticLibA.h
#ifndef _STATIC_LIBA_HEADER
#define _STATIC_LIBA_HEADER
int hello(void);
int hello_staticLibA_only(void);
#endif
Run Code Online (Sandbox Code Playgroud)
staticLibA.cpp
#include "staticLibA.h"
int hello(void)
{
printf("\nI'm in staticLibA\n");
return 0;
}
int hello_staticLibA_only(void)
{
printf("\nstaticLibA: hello_staticLibA_only\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
g++ -c -Wall -fPIC -m32 -o staticLibA.o staticLibA.cpp
ar -cvq ../libstaticLibA.a staticLibA.o
a - staticLibA.o
Run Code Online (Sandbox Code Playgroud)
staticLibB.h
#ifndef _STATIC_LIBB_HEADER
#define _STATIC_LIBB_HEADER
int hello(void);
int hello_staticLibB_only(void);
#endif
Run Code Online (Sandbox Code Playgroud)
staticLibB.cpp
#include "staticLibB.h"
int hello(void)
{
printf("\nI'm in staticLibB\n");
return 0;
}
int hello_staticLibB_only(void)
{
printf("\nstaticLibB: hello_staticLibB_only\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出: …