我正在尝试使用XCode 5.1.1和Cuda Toolkit 6在MacOS X Mavericks上构建C ++ \ Cuda应用程序。
我在链接期间收到以下错误:
Undefined symbols for architecture x86_64:
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in bmp-read.cu.o
___cxx_global_var_init in encoder_nostream.cu.o
___cxx_global_var_init in encoder_stream.cu.o
___cxx_global_var_init in tier1.cu.o
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in bmp-read.cu.o
___cxx_global_var_init in encoder_nostream.cu.o
___cxx_global_var_init in encoder_stream.cu.o
___cxx_global_var_init in tier1.cu.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我尽可能尝试使用libstdc ++( - lddc ++)选项,但没有运气。
这是makefile的一部分:
# Compilers
NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc
CXX := g++
CC := gcc
LINK := g++ -fPIC
# Includes
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc
# architecture flag for cubin build
CUBIN_ARCH_FLAG := -m32
# Warning flags
CXXWARN_FLAGS := \
-W -Wall \
-Wimplicit \
-Wswitch \
-Wformat \
-Wchar-subscripts \
-Wparentheses \
-Wmultichar \
-Wtrigraphs \
-Wpointer-arith \
-Wcast-align \
-Wreturn-type \
-Wno-unused-function \
$(SPACE)
CWARN_FLAGS := $(CXXWARN_FLAGS) \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wnested-externs \
-Wmain \
# Compiler-specific flags
NVCCFLAGS := -ccbin /usr/bin/clang -arch=sm_30 --compiler-options -Wall,-ansi,-Wno-extra-tokens -Xcompiler -stdlib=libstdc++
CXXFLAGS := $(CXXWARN_FLAGS) -stdlib=libstdc++
CFLAGS := $(CWARN_FLAGS) -stdlib=libstdc++
...
LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER)
LIB += -lstdc++$(LIBSUFFIX)
答案 0 :(得分:2)
诀窍在于将-stdlib = libstdc ++传递给链接器。
LINK := g++ -fPIC -stdlib=libstdc++