[英](make/g++) include full path of auto-generated dependency targets? (or workaround)
[short version] I can't have two source files with the same name in my unit tested c++ project even though they are in different folders. [简短版本]在经过单元测试的c ++项目中,我不能有两个名称相同的源文件,即使它们位于不同的文件夹中。 g++ and make are grumpy with each other.
g ++和make彼此脾气暴躁。 (Or maybe I'm being stupid)
(或者我很蠢)
[long version] I've run into a problem with my make/g++/gtest setup. [长版]我的make / g ++ / gtest设置遇到了问题。 When g++ auto-generates dependencies, it generates something like this:
当g ++自动生成依赖关系时,它会生成如下内容:
event_handler.o: src/os/event_handler.h src/os/event.h
But I need something like this (full path of target): 但是我需要这样的东西(目标的完整路径):
src/os/event_handler.o: src/os/event_handler.h src/os/event.h
The reason is when I have a file like this: 原因是当我有这样的文件时:
src/os/event_handler.cpp // contains EventHandler class
I have a companion file like this: 我有一个这样的伴随文件:
test/src/os/event_handler.cpp // contains EventHandlerTest unit test class
... so their .o files both just show up as event_handler.o in the auto-generated dependency list. ...因此它们的.o文件都只是在自动生成的依赖项列表中显示为event_handler.o。 Is there a way to force g++ to give the full path or do I need to change the names of my test files to something like:
有没有一种方法可以强制g ++提供完整路径,或者我需要将测试文件的名称更改为类似以下内容:
test/src/os/event_handler_test.cpp
I wasn't able to find anything online or in the documentation. 我无法在线或在文档中找到任何内容。
There are two solutions. 有两种解决方案。
Personally I prefer the MMD solutions, as it also tends to work better with buggy header files. 就我个人而言,我更喜欢MMD解决方案,因为它也可以更好地解决有问题的头文件。 See http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html
参见http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.