c++ - G++编译,mac os和ubuntu的区别

标签 c++ ubuntu makefile g++

我有一个如下所示的 C++ 项目,

-project/
    -include/   --> .hpp files
    -src/       --> .cpp files
    -bin/       --> for output executable
    -makefile

我的makefile如下,

g++ src/* -I include/ -o bin/program

当我运行 makefile 时,它在我的 Mac OS 上运行得很好。但是,我尝试使用我的 Ubuntu 编译它,但没有成功。我有以下错误,

src/SomeFileName.cpp:1:28: fatal error: SomeFileName.hpp: No such file or directory
compilation terminated.
src/main.cpp:1:28: fatal error: SomeFileName.hpp: No such file or directory
compilation terminated.

我应该专门为 Ubuntu 更改 makefile 的某些部分吗?有什么问题?

我的 ubuntu g++ 版本:

x@x:~$ g++ --version
g++ (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3

我的main.cpp如下,

#include "ListController.hpp"
#include <time.h>

int main() {
    doStuff();
    return 0;
}

最佳答案

我唯一可以假设的是,在您的 Mac 上,PATH 环境变量还包含 ./

因此,您可以尝试通过以下方式更改您的 makefile:

g++ ./src/* -I ./include/ -o ./bin/program

关于c++ - G++编译,mac os和ubuntu的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19890511/

相关文章:

node.js - npm 在 Ubuntu 16.04 上删除了 Plesk 12

java - Apache Spark : Pre requisite questions

c++ - Eclipse C/C++ 显示错误但编译?

c++ - 模板类模板成员的模板特化

c++ - 检查conhost打印需要多长时间

bash - 如何通过在 ubuntu 中包含 "cd"命令来运行 shell 脚本?

linux - 如何在c中制作一个 'makefile'

c - 如何正确地将 msgpack 链接到共享库中

c - VS code c编程,如何修复-Makefile :2: *** missing separator. Stop.?

c++ - 访问类中定义的友元函数