在 OS X 上使用 yaml-cpp 时出现问题
因此,我在编译使用 yaml-cpp 的应用程序时遇到问题,
我在源文件中包含“yaml.h”(就像 yaml-cpp wiki 中的示例一样),但是当我尝试编译应用程序时,我得到了以下错误:
g++ -c -o entityresourcemanager.o entityresourcemanager.cpp
entityresourcemanager.cpp:2:18: error: yaml.h: No such file or directory
make: *** [entityresourcemanager.o] Error 1
我的 makefile 如下所示:
CC = g++
CFLAGS = -Wall
APPNAME = game
UNAME = uname
OBJECTS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
mac: $(OBJECTS)
$(CC) `pkg-config --cflags --libs sdl` `pkg-config --cflags --libs yaml-cpp` $(CFLAGS) -o $(APPNAME) $(OBJECTS)
pkg-config --cflags --libs yaml-cpp 返回:
-I/usr/local/include/yaml-cpp -L/usr/local/lib -lyaml-cpp
并且 yaml.h 确实位于 /usr/local/include/yaml-cpp
任何想法我能做什么?
谢谢
So I'm having trouble compiling my application which is using yaml-cpp
I'm including "yaml.h" in my source files (just like the examples in the yaml-cpp wiki) but when I try compiling the application I get the following error:
g++ -c -o entityresourcemanager.o entityresourcemanager.cpp
entityresourcemanager.cpp:2:18: error: yaml.h: No such file or directory
make: *** [entityresourcemanager.o] Error 1
my makefile looks like this:
CC = g++
CFLAGS = -Wall
APPNAME = game
UNAME = uname
OBJECTS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
mac: $(OBJECTS)
$(CC) `pkg-config --cflags --libs sdl` `pkg-config --cflags --libs yaml-cpp` $(CFLAGS) -o $(APPNAME) $(OBJECTS)
pkg-config --cflags --libs yaml-cpp returns:
-I/usr/local/include/yaml-cpp -L/usr/local/lib -lyaml-cpp
and yaml.h is indeed located in /usr/local/include/yaml-cpp
Any idea what I could do?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的默认目标是“mac”,并且您有如何构建它的规则。它取决于目标文件,并且您没有任何如何构建这些文件的规则,因此 make 使用其隐式规则。这些规则就是这样做的:
正如您所看到的,这里没有
-I/usr/local/...
部分。解决此问题的最简单方法是全局更改 CPPFLAGS 和 LDFLAGS 值:
CPPFLAGS 值由从 cpp 文件构建对象文件的隐式规则使用,因此现在编译器应该找到 yaml 标头。
编辑:
LDFLAGS
可能应该在OBJECTS
之后Your default target is "mac" and you have rule how to build it. It depends on object files and you do not have any rules how to build those, so make is using its implicit rules. Those rules do just that:
As you can see there is no
-I/usr/local/...
part here.The easiest way to fix that is to change CPPFLAGS and LDFLAGS value globally:
CPPFLAGS
value is used by implicit rules that build object files from cpp files, so now compiler should find yaml headers.Edit:
LDFLAGS
probably should go afterOBJECTS
你的包含目录不匹配吗?
-I/usr/local/include
而不是
-I/usr/local/include/yaml-cpp
Don't you mismatch your include directory?
-I/usr/local/include
instead of
-I/usr/local/include/yaml-cpp