mac构建有一个未定义的符号,而linux构建并没有用于相同的代码
mac build has undefined symbol where linux build did not for same code
我们有适用于mac的gcc 4.2和适用于linux的gcc 4.4。当我构建相同的代码时,我得到以下未定义的符号:
"MyClassNameSpecific1::MyClassNameSpecific1(int,int,int、className::class1 const&,className:;class2 const&&;、int,int)",引用自:MyOtherClassName::MyOtherClassName.o中的mContainer()ld:找不到体系结构x86_64 的符号
MyClassName.h:的代码如下
class MyClassNameSpecific1;
class MyClassNameSpecific2;
class MyClassNameSpecific1
{
public:
MyClassNameSpecific1(const string ¶m1);
virtual ~MyClassNameSpecific1() {}
}
class MyClassNameSpecific2: public classU::UData
{
public:
MyClassNameSpecific2(int width, int height, int breadth, const className::class1 &dType, const className::class2 &layout, int tWidth, int tHeight);
};
MyClassName.cpp有这个:
#include "MyClassName.h"
MyClassNameSpecific1::MyClassNameSpecific1(const string ¶m1) : classU::UData()
{
//does things here
}
MyClassNameSpecific2::MyClassNameSpecific2(int width, int height, int breadth, const className::class1 &dType, const className::class2 &layout, int tWidth, int tHeight) : classU::UData()
{
//does things here
}
我不确定是什么原因导致了一场不败,但另一场却没有。有人知道gcc在这种情况下有什么不同吗?我的makefile包含所有类:MyClassName,然后是其他类。我看不出MyClassNameSpecific2的.h和.cpp文件之间的参数签名有任何差异。
我试着确保在.h和.cpp文件中都使用了完整的className::class1,但它仍然有相同的undef。此外,我尝试添加类MyClassNameSpecific2,其中它在MyClassName.h文件的顶部只有类MyClassName Specific1,但它没有更改undef。我试着在谷歌上搜索这个问题,但没有找到任何相关的信息。也许还有其他东西我可以搜索,但我不确定。我在.h和.cpp文件中省略了小类定义的#includes。
如果有人可以尝试,那就太好了,即使这是我没有想到的参数的不同命名法。
添加了makefile:
.SUFFIXES: .cpp
DEP_DIR = ../dependencies
CC = g++
OS := $(shell uname -s)
ifeq ($(OS),Darwin)
#set LIB_DIR
LIB_DIR1=darwin64_gcc42/lib
LIB_DIR2=darwin64_gcc44/lib
else
LIB_DIR=linux64_gcc44/lib
endif
INCDIRS = -I. -I../include
-I$(DEP_DIR)/className/include
-I$(DEP_DIR)/classNameOther/include
#C++FLAGS = -c -fPIC -g -O2 -DLINUX -D_DEBUG -D_FILE_OFFSET_BITS=64 -m64 -Wall
C++FLAGS = -c -fPIC -O2 -DLINUX -DNDEBUG -D_FILE_OFFSET_BITS=64 -m64 -Wall
ifeq ($(OS),Darwin)
LDFLAGS = -m64 -pthread -ldl -shared -L../$(LIB_DIR1)/release
-L$(DEP_DIR)/className/$(LIB_DIR1)
-L$(DEP_DIR)/classNameOther/$(LIB_DIR2)/release
else
LDFLAGS = -m64 -pthread -ldl -shared -L../$(LIB_DIR)/release
-L$(DEP_DIR)/className/$(LIB_DIR)
-L$(DEP_DIR)/classNameOther/$(LIB_DIR)/release
endif
LDLIBS = -llittleClass -lclassName -lclassNameOther -lclassNameOthermalloc
all: MyClassName MyOtherClassName AnotherClass2 AnotherClass3 AnotherClass4 AMoreOverallClass
AMoreOverallClass: AMoreOverallClass.o
$(CC) AMoreOverallClass.o $(LDFLAGS) -o $@ $(LDLIBS)
...
.cpp.o:
$(CC) $(C++FLAGS) $(INCDIRS) $< -o $@
clean:
rm -rf *.o all
以下是在命令行进行输出:
mcle@engmacvi01(577)% make
g++ -c -fPIC -O2 -DLINUX -DNDEBUG -D_FILE_OFFSET_BITS=64 -m64 -Wall -I. -I../include -I../dependencies/className/include -I../dependencies/classNameOther/include MyClassName.cpp -o MyClassName.o
g++ MyClassName.o -m64 -pthread -ldl -shared -L../darwin64_gcc42/lib/release -L../dependencies/className/darwin64_gcc42/lib -L../dependencies/classNameOther/darwin64_gcc44/lib/release -o MyClassName-ludm -lclassName -lclassNameOther -lclassNameOthermalloc
g++ -c -fPIC -O2 -DLINUX -DNDEBUG -D_FILE_OFFSET_BITS=64 -m64 -Wall -I. -I../include -I../dependencies/className/include -I../dependencies/classNameOther/include AnotherClass.cpp -o AnotherClass.o
g++ AnotherClass.o -m64 -pthread -ldl -shared -L../darwin64_gcc42/lib/release -L../dependencies/className/darwin64_gcc42/lib -L../dependencies/classNameOther/darwin64_gcc44/lib/release -o AnotherClass -llittleClass -lclassName -lclassNameOther -lclassNameOthermalloc
Undefined symbols for architecture x86_64:
"MyClassNameSpecific1::MyClassNameSpecific1(int, int, int, className::class1 const&, className::class2 const&, int, int)", referenced from:
AnotherClass::mContainer() in AnotherClass.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [AnotherClass] Error 1
此外,MyOtherClassName.cpp:
UReturnClass &MyOtherClassName::mContainer()
{
if (!m_mContainerPtr)
{
m_mContainerPtr = new UReturnClass();
UMPtr md = new MyClassNameSpecific2(m_width, m_height, m_bands, m_dataType, m_dataLayout, m_tileWidth, m_tileHeight);
m_mContainerPtr->setMdata(md);
}
return *m_mContainerPtr;
}
MyOtherClassName.h:
className::class1 m_dType;className::class2 m_dLayout;
修复方法是更改makefile,使其在一个步骤中构建所有文件,而不是为每个类单独执行步骤,因为他们试图分别链接以获取每个类的.o文件,然后再将其全部放在一起。我不知道为什么linux版本可以单独做这件事,而mac版本则不然。更改类名以保护无辜者。
SRCS=UMetaPlugin.cpp UDataPlugin..cpp UForPlugin.cppp UFacPlugin.cppUMTransPlugin.cpp-UPlugin.cpp
objects=$(patsubst%.cpp,%.o,$(SRCS))
全部:$(appn)
$(appn):$(对象)$(CC)$(LDFLAGS)-o$@$(对象)$(LDIBS)
.cpp.o:$(CC)$(C++FLAGS)$(INCDIRS)$<-o$@
- FLTK 2.0构建和演示,适用于VS2019的2011年左右的代码库
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- meson-build:wxWidgets 资源文件,用于 Windows 未构建
- 用于构建 cuda .so 文件(共享库)的生成文件
- 用于自定义调试构建的 CMake qt 输入库后缀
- C++查找用于构建单行计算器
- 使用VS2017构建用于Linux的Protobuf
- 构建共享对象 - 使用 Ninja 编译适用于 OSX 和 Windows 上的 Ubuntu Crush
- MoltenVK(适用于 Vulkan)构建在 OS X v. 10.13.3 (17D102) 上失败 |Xcode
- 在构建之前,如何使Cmake在构建之前运行Python脚本,以生成用于构建中的项目的文件
- 用于构建 POCO 库的 mysql 连接器
- 构建适用于 iOS 的 ICU
- Cmake:如何构建自定义编译器二进制文件,然后将其用于某些目标?
- mac构建有一个未定义的符号,而linux构建并没有用于相同的代码
- 在霍夫曼压缩后将代码表存储在压缩文件中,并从此表构建用于解压缩的树
- 同时构建用于提升的32位和64位库
- 用g++构建用于MSVC应用程序的dll
- 正在构建用于Oracle jvm的avahi(错误:jni.h未找到)
- 在Xcode 4中构建用于Objective-c应用程序的静态c++库
- 正在构建用于编译boost的Openssl源代码