2017-04-21 52 views
2

我一起使用C和C++代碼時遇到了問題。該「使」命令返回「未定義提到功能」中所有功能SPConfig.cSPLogger.c,當所謂的從SPImageProc.cpp

的#include這些相關文件中的節在下面給出:
未定義的引用功能錯誤,一起使用C和C++

SPLogger.c

#include "SPLogger.h" 
#include <stdio.h> 
#include <stdlib.h> 
#include <stdbool.h> 
#include <string.h> 

SPConfig.h

#ifndef SPCONFIG_H_ 
#define SPCONFIG_H_ 

#include <stdbool.h> 
#include <stdio.h> 
#include "SPLogger.h" 
//Functions definitions 
#endif /* SPCONFIG_H_ */ 

SPConfig.c

#include "SPConfig.h" 
#include <stdio.h> 
#include <stdlib.h> 
#include <stdbool.h> 
#include <string.h> 

SPImageProc.h

#ifndef SPIMAGEPROC_H_ 
#define SPIMAGEPROC_H_ 
#include <opencv2/core.hpp> 
#include <opencv2/imgcodecs.hpp> 
#include <vector> 

extern "C" { 
#include "SPConfig.h" 
#include "SPPoint.h" 
} 

namespace sp { 
//Class and function definitions 
} 

SPImageProc.cpp

#include <cstdlib> 
#include <cassert> 
#include <cstring> 
#include <opencv2/xfeatures2d.hpp> 
#include <opencv2/core.hpp> 
#include <opencv2/imgproc.hpp> 
#include <opencv2/imgcodecs.hpp> 
#include <opencv2/highgui.hpp> 
#include <cstdio> 
#include "SPImageProc.h" 
extern "C" { 
#include "SPLogger.h" 
} 

的Makefile

CC = gcc 
CPP = g++ 
#put all your object files here 
OBJS = main.o SPImageProc.o SPPoint.o 
#The executabel filename 
EXEC = SPCBIR 
INCLUDEPATH=/usr/local/lib/opencv-3.1.0/include/ 
LIBPATH=/usr/local/lib/opencv-3.1.0/lib/ 
LIBS=-lopencv_xfeatures2d -lopencv_features2d \ 
-lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_core 


CPP_COMP_FLAG = -std=c++11 -Wall -Wextra \ 
-Werror -pedantic-errors -DNDEBUG 

C_COMP_FLAG = -std=c99 -Wall -Wextra \ 
-Werror -pedantic-errors -DNDEBUG 

.PHONY: all clean 

all: $(EXEC) 

$(EXEC): $(OBJS) 
    $(CPP) $(OBJS) -L$(LIBPATH) $(LIBS) -o [email protected] 
main.o: main.cpp #put dependencies here! 
    $(CPP) $(CPP_COMP_FLAG) -I$(INCLUDEPATH) -c $*.cpp 
#a rule for building a simple c++ source file 
#use g++ -MM SPImageProc.cpp to see dependencies 
SPImageProc.o: SPImageProc.cpp SPImageProc.h SPConfig.h SPPoint.h SPLogger.h 
    $(CPP) $(CPP_COMP_FLAG) -I$(INCLUDEPATH) -c $*.cpp 
#a rule for building a simple c source file 
#use "gcc -MM SPPoint.c" to see the dependencies 

SPPoint.o: SPPoint.c SPPoint.h 
    $(CC) $(C_COMP_FLAG) -c $*.c 
clean: 
    rm -f $(OBJS) $(EXEC) 

有些Makefile中的錯誤:

SPImageProc.o: In function `sp::ImageProc::initFromConfig(sp_config_t*)': 
SPImageProc.cpp:(.text+0xc8): undefined reference to `spConfigGetPCADim' 
SPImageProc.cpp:(.text+0xf2): undefined reference to `spLoggerPrintError' 
SPImageProc.cpp:(.text+0x12c): undefined reference to `spConfigGetNumOfImages' 

我已經在各自的C和CPP文件實現的功能。我已經嘗試了很多來自己修復它,並在Stack Overflow上查找類似的問題,但找不到解決方案。請幫忙。

回答

1

您還沒有連接SPLogger.oSPConfig.o

甚至編譯它們對這一問題。

您需要添加制定規則SPLogger.oSPConfig.o類似於SPImageProc.o,您需要將它們添加到OBJS

+0

非常感謝你的解答。我編輯了makefile以鏈接SPLogger.o和SPConfig.o。現在正在編譯。再次感謝。 –

相關問題