2017-04-18 1 views
-2

두 테스트 모두에서 node.c, list.c 및 helper-functions.c를 컴파일하려고합니다.링키지 C 및 C++ 파일

필자는 꼭 makefile을 작성하지 않았을 것입니다. 체크 아웃 해 주실 수 있습니까?

CFLAGS= -Wall -Wvla -Werror 
CXXFLAGS= -lgtest -lgtest_main -pthread 

all: 
    mkdir -p build 
    gcc -c node.c $(CFLAGS) -o build/node.o 
    gcc -c list.c $(CFLAGS) -o build/list.o 
    gcc -c tests/helper-functions.c -o build/helper-functions.o 
    g++ tests/node-tests.cpp $(CXXFLAGS) -o build/node-tests.o 
    g++ tests/list-tests.cpp $(CXXFLAGS) -o build/list-tests.o 
    g++ build/list.o build/node.o build/helper-functions.o build/node-tests.o build/list-tests.o -o build/tests.out 
    ./build/tests.out 

내가 make를 실행하는 경우, 출력은 다음

mkdir -p build 
gcc -c node.c -Wall -Wvla -Werror -o build/node.o 
gcc -c list.c -Wall -Wvla -Werror -o build/list.o 
gcc -c tests/helper-functions.c -o build/helper-functions.o 
g++ tests/node-tests.cpp -lgtest -lgtest_main -pthread -o build/node-tests.o 
/tmp/ccFTgPVe.o: In function `CreateNode_FirstTest_Test::TestBody()': 
node-tests.cpp:(.text+0x21): undefined reference to `createNode' 
node-tests.cpp:(.text+0x31): undefined reference to `data' 
node-tests.cpp:(.text+0x108): undefined reference to `next' 
node-tests.cpp:(.text+0x1db): undefined reference to `freeNode' 
collect2: error: ld returned 1 exit status 
make: *** [all] Error 1 

definitly 노드 Test.cpp에 모든 이러한 기능에 대한 참조가있다.

노드 tests.cpp는 :

extern "C" 
{ 
    #include "../../../../headers/list.h" 
    #include "../../../../headers/node.h" 
    #include "helper-functions.h" 
    #include <assert.h> 
} 
#include "gtest/gtest.h" 
#include <iostream> 
#include <cstdlib> 
#include <string> 


// Node* CreateNode(void* data,const size_t dataLength,void* deepCopy(void*,const size_t)); 

TEST(CreateNode, FirstTest) { 

    int x=10; 
    Node* pos=createNode(&x,sizeof(x)); 
    EXPECT_TRUE(*(int*)data(pos)==x); 
    EXPECT_TRUE(next(pos)==NULL); 
    freeNode(pos); 
} 

목록 - tests.cpp는 노드 tests.cpp 유사하다. [I 고칠 어떻게 정의되지 않은 참조/확인되지 않은 외부 기호 오류이며 무엇?]의

+1

가능한 중복 (http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference -unresolved-external-symbol-error-and-do-do-i-fix) – Olaf

+0

괜찮 으면 내 메이크 파일을 확인할 수 있습니까? if Not pls는 거기에 27 명이 있기 때문에 관련 답변을 참조합니다. –

+0

우리는 무료 디버깅 서비스가 아닙니다. 사본이 당신의 퀘스트에 응답해야합니다. 그렇지 않은 경우 ** 특정 문제 ** 및 dup에있는 문제와 다른 점을 명시하십시오! – Olaf

답변

0
CFLAGS= -Wall -Wvla -Werror 
CXXFLAGS= -lgtest -lgtest_main -pthread 

all: 
    mkdir -p build 
    gcc -c node.c $(CFLAGS) -o build/node.o 
    gcc -c list.c $(CFLAGS) -o build/list.o 
    gcc -c tests/helper-functions.c $(CFLAGS) -o build/helper-functions.o 
    g++ -c tests/node-tests.cpp -o build/node-tests.o //added -c, removed $(CXXFLAGS) 
    g++ -c tests/list-tests.cpp -o build/list-tests.o // added -c, $(CXXFLAGS) 
    g++ build/list.o build/node.o build/helper-functions.o build/node-tests.o build/list-tests.o $(CXXFLAGS) -o build/tests.out // added $(CXXFLAGS) 
    ./build/tests.out