【问题标题】:Can't include header in cpp file不能在 cpp 文件中包含标头
【发布时间】:2012-03-02 20:35:00
【问题描述】:

我希望将其包含在我的 cpp 文件中:

#include <boost/lambda/lambda.hpp>

对于我的 Makefile 项目,我选择了 Properties>Path and Symbols>GNU C++>Include Directories> 并补充说:

/opt/local/include

但是当我尝试构建时出现此错误:

**** Build of configuration Default for project Main ****

make all 
g++ -O2 -g -Wall  -fmessage-length=0   -c -o Main.o Main.cpp
Main.cpp:107:35: error: boost/lambda/lambda.hpp: No such file or directory

可能是什么问题?

文件 /opt/local/include/boost/lambda/lambda.hpp 存在。

这是我的生成文件:

CXXFLAGS =  -O2 -g -Wall  -fmessage-length=0

SRCS =      Main.cpp 
OBJS =      Main.o 
LIBS =      -framework CoreMIDI -framework CoreAudio -framework CoreFoundation -framework CoreServices

TARGET =    Main 

$(TARGET):  $(OBJS)
    $(CXX) -Wall -D__MACOSX_CORE__ -o $(TARGET) $(SRCS) $(LIBS)

all:    $(TARGET)

clean:
    rm -f $(OBJS) $(TARGET)

【问题讨论】:

  • /opt/local/include 在您的库路径中吗?我不知道它是否默认在 Linux 上。
  • 调用行似乎缺少-I /opt/local/include。可能是某处设置了环境变量,但这不太可能。再次检查您的配置设置。
  • 我已将 CXXFLGAS += -I/opt/local/include 添加到生成文件中,但仍然没有运气。我做错了什么?
  • @KerrekSB 更好:-isystem。这可以防止一堆不相关的警告,并允许您使用 -Werror 集进行编译。
  • 注意拼写错误:CXXFLGAS 应该是 CXXFLAGS

标签: c++ eclipse makefile gnu-make


【解决方案1】:

应该可以。

CXXFLAGS =  -O2 -g -Wall  -fmessage-length=0

SRCS =      Main.cpp 
OBJS =      Main.o 
LIBS =      -framework CoreMIDI -framework CoreAudio -framework CoreFoundation -    framework CoreServices
INCL_DIR = /opt/local/include
TARGET =    Main 

$(TARGET):  $(OBJS)
$(CXX) -Wall -D__MACOSX_CORE__ -o $(TARGET) $(SRCS) $(LIBS) -I $(INCL_DIR)

all:    $(TARGET)

clean:
rm -f $(OBJS) $(TARGET)

【讨论】:

    猜你喜欢
    • 2017-08-18
    • 2014-01-04
    • 2022-11-27
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多