C++ 无法在C+;上编译包Helloworld+;用于OpenWrt
我正在尝试为OpenWrt编译简单的helloworld程序(使用构建系统,分支17.01.6)。我使用了两个教程:第2部分C++。 但在编译helloworld包期间,我遇到错误:C++ 无法在C+;上编译包Helloworld+;用于OpenWrt,c++,makefile,openwrt,C++,Makefile,Openwrt,我正在尝试为OpenWrt编译简单的helloworld程序(使用构建系统,分支17.01.6)。我使用了两个教程:第2部分C++。 但在编译helloworld包期间,我遇到错误:包helloworld缺少以下库的依赖项: libc.so.6 文件结构: . ├--openwrt_17_01 ├--源#源目录,生成系统 ├--helloworld#helloworld项目 |└--src |├--helloworld.cpp |└--Makefile#C++项目Makefile └--mypa
包helloworld缺少以下库的依赖项:
libc.so.6
文件结构:.
├--openwrt_17_01
├--源#源目录,生成系统
├--helloworld#helloworld项目
|└--src
|├--helloworld.cpp
|└--Makefile#C++项目Makefile
└--mypackages
└--示例
└--helloworld
└--Makefile#包Makefile
openwrt_17_01/helloworld/src/helloworld.cpp:
#include "stdio.h"
int main()
{
printf("Hello, world! (C++)\n\n");
return 0;
}
openwrt_17_01/helloworld/src/Makefile:
helloworld: helloworld.o
$(CXX) $(LDFLAGS) helloworld.o -o helloworld $(LIBS)
helloworld.o: helloworld.cpp
$(CXX) $(CXXFLAGS) -c helloworld.cpp
clean:
rm *.o helloworld
include $(TOPDIR)/rules.mk
PKG_NAME:=helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=1
SOURCE_DIR:=/home/mzhi/proj_src/openwrt_17_01/helloworld
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/helloworld
SECTION:=examples
DEPENDS:= +libstdcpp +libc
CATEGORY:=Examples
TITLE:=Hello, World!
endef
define Package/helloworld/description
A simple "Hello, world!" -application.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) $(SOURCE_DIR)/src/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
LIBS="-nodefaultlibs -lgcc -lc -luClibc++" \
LDFLAGS="$(EXTRA_LDFLAGS)" \
CXXFLAGS="$(TARGET_CFLAGS) $(EXTRA_CPPFLAGS) -nostdinc++" \
$(TARGET_CONFIGURE_OPTS) \
CROSS="$(TARGET_CROSS)" \
ARCH="$(ARCH)" \
$(1);
endef
define Package/helloworld/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin
endef
$(eval $(call BuildPackage,helloworld))
mypackages/examples/helloworld/Makefile:
helloworld: helloworld.o
$(CXX) $(LDFLAGS) helloworld.o -o helloworld $(LIBS)
helloworld.o: helloworld.cpp
$(CXX) $(CXXFLAGS) -c helloworld.cpp
clean:
rm *.o helloworld
include $(TOPDIR)/rules.mk
PKG_NAME:=helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=1
SOURCE_DIR:=/home/mzhi/proj_src/openwrt_17_01/helloworld
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/helloworld
SECTION:=examples
DEPENDS:= +libstdcpp +libc
CATEGORY:=Examples
TITLE:=Hello, World!
endef
define Package/helloworld/description
A simple "Hello, world!" -application.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) $(SOURCE_DIR)/src/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
LIBS="-nodefaultlibs -lgcc -lc -luClibc++" \
LDFLAGS="$(EXTRA_LDFLAGS)" \
CXXFLAGS="$(TARGET_CFLAGS) $(EXTRA_CPPFLAGS) -nostdinc++" \
$(TARGET_CONFIGURE_OPTS) \
CROSS="$(TARGET_CROSS)" \
ARCH="$(ARCH)" \
$(1);
endef
define Package/helloworld/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin
endef
$(eval $(call BuildPackage,helloworld))
编译的完整输出(生成包/helloworld/compile-j1 V=s):
操作系统:ubuntu 16.04目标系统:联发科Rilink MIPS
子目标:基于MT7621的板
目标概况:泛素EdgeRouter X
谷歌搜索了很多,但我仍然无法理解为什么编译器没有看到必要的libc.so.6库,以及如何在Makefile中正确连接它
可能有人已经遇到过类似的问题,请分享解决方案。将您的Makefile更改为这个怎么样
BINARY = helloworld$(EXE)
FILES = helloworld.o
all: $(BINARY)
helloworld$(EXE): $(FILES)
$(CC) $(FILES) -o $(@)
clean:
rm -f $(FILES) *.o
这个的代码是:
#include <stdio.h>
int main()
{
printf("Hello, world! (C++)\n\n");
return 0;
}
#包括
int main()
{
printf(“你好,世界!(C++)\n\n”);
返回0;
}
您想要的答案如下:
您必须将
$(CC)
更改为$(CXX)
和$(CFLAGS)
更改为$(cxflags)
您的代码是否编译在文件夹openwrt\u 17\u 01/helloworld/src/
中?如果有,请尝试该文件夹中的makeclean
,然后再次启动该过程。@bernatpedrovozmediano是的,代码在openwrt\u 17\u 01/helloworld/src/
中成功编译,是的,我在那之后做了makeclean
,这可能是一个更全球性的问题。在此之前,我试图使用iostream
编译一个程序,编译器诅咒了这个指令,然后我删除了这个代码,并在没有iostream
的情况下制作了一个最简单的示例,但是现在出现了这个错误,谢谢您的版本。我尝试了它,并且make
insideopenwrt_17_01/helloworld/src/
工作(和前面的一个一样工作),但是当我运行make-package/helloworld/compile-j1 V=s
insideopenwrt_17_01/source
目录时仍然会发生相同的错误。另外,我想要C++编译器,而不是C,因为将来我打算编写程序并编译C++上的OpenWRT包。