如何解决编译错误 - makefile

时间:2013-03-27 12:47:28

标签: linux gcc makefile wxwidgets

我修改了一个makefile并尝试编译一个项目。但它只是在第一步失败了。

即使我已经指定了编译的模式规则,w.r.t: -
http://www.gnu.org/software/make/manual/make.html#Static-Usage

Makefile是: -

# topdir for wxWidgets base 
top_builddir = /opt/wxgtk
EXTRALIBS = -pthread -lz -ldl -lm
LDLIBS = ${APPEXTRALIBS} ${top_builddir}/lib/libwx_baseu-2.8.a ${EXTRALIBS}
CXX         = c++

CXXFLAGS = -g -O0 -pthread -I/usr/include/SDL -D_REENTRANT -Wall -Wno-ctor-dtor-privacy
CPPFLAGS = -D__WXDEBUG__  -I${top_builddir}/wx/include/base-unicode-release-static-2.8  -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D_LARGEFILE_SOURCE=1
CFLAGS = ${APPEXTRACFLAGS} ${CPPFLAGS} -O2 -MMD -pthread -Wall
CFLAGS  += -DLINUX

CANALOBJS =     ../../common/listenthread_unix.o ../../common/clientthread_level1_unix.o ../../common/devicethread_unix.o \
        ../../common/canalshmem_level1_unix.o ../../common/clientlist.o ../../common/controlobject.o \
        ../../common/devicelist.o ../../common/udpreceivethread_unix.o ../../../vscp/common/vscp.o \
        ../../common/clientthread_level2_unix.o ../../common/canalshmem_level2_unix.o \
        ../../common/tcplistenthread.o
CANALHDRS = ../../common/clientlist.h ../../common/controlobject.h ../../common/devicelist.h \
        ../../common/canal.h ../../common/canaldlldef.h \
        ../../common/version.h ../../common/canal_unix_ipc.h ../../common/CanalShMem_level1_unix.h \
        ../../common/CanalShMem_level2_unix.h ../../common/clientthread_level1_unix.h ../../common/clientthread_level2_unix.h
PROJOBJS    = ../../../common/dllist.o ../../../common/configfile.o ../../../common/crc.o
PROJHDRS    = ../../../common/dllist.h ../../../common/configfile.h
OBJS        = canald.o
HDRS        = canald.h

all:        canald

# Build the Linux executable
canald:     $(OBJS) $(HDRS) $(CANALOBJS) $(CANALHDR) $(PROJOBJS) $(PROJHDRS)
        $(CXX)  -o canald $(OBJS) $(CANALOBJS) $(PROJOBJS) -L$(LIBS) $(LDLIBS)

$(OBJS) $(CANALOBJS) $(PROJOBJS):%.o: %.cpp
        $(CXX) -c $(CFLAGS) $< -o $@

我得到的错误: -

make
make: *** No rule to make target `canald.cpp', needed by `canald.o'.  Stop.

请建议如何解决此错误?

编辑:-------

文件丢失了...正在编译......但是收到了以下错误

vscpd.cpp:47:19: fatal error: wx/wx.h: No such file or directory
compilation terminated.
make: *** [vscpd.o] Error 1

我在以下位置安装了wxgtk:---

/opt/wxgtk

.profile被修改: -

PATH = $PATH:/opt/wxgtk
export LD_LIBRARY_PATH=/usr/lib:/usr/local/lib:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/opt/wxgtk/lib:$LD_LIBRARY_PATH

Make无法找到

#include<wx/wx.h> 

如何解决?

1 个答案:

答案 0 :(得分:1)

必须使用wx-config而不是直接指定包含路径,请参阅例如this answer

你的makefile非常奇怪,因为你定义CXXFLAGS只是为了永远不会使用它,而是使用CPPFLAGS作为CFLAGS的一部分。因此,在您的情况下,您需要将CPPFLAGS定义替换为wx-config调用,例如

WX_CONFIG := /opt/wxgtk/bin/wx-config
CPPFLAGS := $(shell $(WX_CONFIG) --cxxflags)

更好的是,摆脱CPPFLAGS并定义CXXFLAGS,并使用它。

同时更新您的LDLIBS以使用wx-config

LDLIBS := ${APPEXTRALIBS} $(shell $(WX_CONFIG) --libs)

(通常不再需要EXTRALIBS)。