자택경비대

Makefile에서 dependency가 누락되는 현상 해결법

Programming

예를 들면 다음과 같다:

all: foo bar

foo:
    echo foo

bar:
    echo bar

이렇게 Makefile이 존재할 때 make all을 하면 foo는 실행되는데 bar은 안된다던가, bar는 실행되지만 foo를 건너뛰는 등의 경우이다.

이런 경우에는 같은 폴더에 foo, bar과 같은 이름의 폴더가 존재하기 때문에 이런 결과가 나타난다.

해결방법은 .PHONY 구문을 이용하여 예외로 지정해주면 간단히 해결된다.

.PHONY: foo bar
all: foo bar

foo:
    echo foo

bar:
    echo bar

google test 컴파일 에러 해결법

Programming

google test는 C++ 단위 테스트 환경 구축을 위한 프레임워크이다.

In file included from sample.cpp:1:
In file included from /usr/local/include/gtest/gtest.h:62:
In file included from /usr/local/include/gtest/internal/gtest-internal.h:40:
/usr/local/include/gtest/internal/gtest-port.h:826:12: error: no member named
      'make_tuple' in namespace 'std'
using std::make_tuple;
      ~~~~~^
/usr/local/include/gtest/internal/gtest-port.h:827:12: error: no member named 'tuple' in
      namespace 'std'
using std::tuple;
      ~~~~~^
/usr/local/include/gtest/internal/gtest-port.h:906:3: warning: deleted function
      definitions are a C++11 extension [-Wc++11-extensions]
  GTEST_DISALLOW_ASSIGN_(RE);
  ^
/usr/local/include/gtest/internal/gtest-port.h:672:34: note: expanded from macro
      'GTEST_DISALLOW_ASSIGN_'
  void operator=(type const &) = delete
                                 ^
/usr/local/include/gtest/internal/gtest-port.h:949:3: warning: deleted function
      definitions are a C++11 extension [-Wc++11-extensions]
  GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
  ^
/usr/local/include/gtest/internal/gtest-port.h:677:24: note: expanded from macro
      'GTEST_DISALLOW_COPY_AND_ASSIGN_'
  type(type const &) = delete; \
...

위의 에러는 google test를 포함한 테스트 코드가 -std=c++11 혹은 이상의 플래그를 포함하지 않아서 발생하는 문제이다.

Makefile의 경우에는 CXXFLAGS=-std=c++11을 추가해주면 해결된다.


+추가내용)

Undefined symbols for architecture x86_64:
"testing::Test::SetUp()", referenced from:
...

위의 경우에는 라이브러리가 연결되지 않아서 발생하는 문제이다.

마찬가지로 Makefile에서는 LDLIBS=-lgtest_main -lgtest -pthread 플래그를 추가하여 해결 할 수 있다.