CppCMS教程:静态链接模板错误:“致命错误:content.h:没有这样的文件或目录”

时间:2013-03-21 15:38:17

标签: c++ cppcms

来自http://cppcms.com/wikipp/en/page/cppcms_1x_tut_hello_templates

我正在按照教程进行操作,下面就是我所做的。

content.h

#include <cppcms/view.h>
#include <string>

namespace content  {
    struct message : public cppcms::base_content {
        std::string text;
    };
}

my_skin.tmpl

<% c++ #include "content.h" %>
<% skin my_skin %>
<% view message uses content::message %>
<% template render() %>
<html>
  <body>
    <h1><%= text %> World!</h1>
  </body>
<html>
<% end template %>
<% end view %>
<% end skin %>

hello.cpp中添加包含:

#include <content.h>

hello.cpp中添加控制器:

virtual void main(std::string /*url*/)
{
    content::message c;
    c.text=">>>Hello<<<";
    render("message",c);
}

当我通过运行my_skin.cpp静态链接hello.cppg++ hello.cpp my_skin.cpp -o hello -lcppcms -lbooster时,会出现以下错误:

hello.cpp:1:21: fatal error: content.h: No such file or directory

我不知道为什么错误,因为hello.cppcontent.h位于同一目录

1 个答案:

答案 0 :(得分:1)

你必须包括然后使用“content.h”

GCC包括&lt;&gt;标签在以下路径中搜索文件

/usr/local/include
libdir/gcc/target/version/include
/usr/target/include
/usr/include
     

参考http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

如果文件位于同一目录中,则可以使用

添加它们
  

包括“fileName.h”

     

在这种情况下,编译器将在当前目录中搜索

但是,您也可以使用-L标志向搜索路径添加任何路径。 示例

  

gcc -L / path / to / library filename.cpp

相关问题