将-m32参数添加到Makefile命令

时间:2013-10-28 22:00:56

标签: c++ makefile

我有一个简单的问题。

这是我的Makefile

#############################################################################
#
#   Makefile for building the Long Range Navigator program
#
#############################################################################

PC = true
#PC = false

PWD       := $(shell pwd)

#GUMSTIX_BUILDROOT   = /home/irmabot/gumstix-buildroot
#BUILD_ARM      = $(GUMSTIX_BUILDROOT)/build_arm_nofpu
#CROSS_COMPILE      = $(BUILD_ARM)/staging_dir/bin/arm-linux-
#BUILD_ARM           = $(wildcard $(GUMSTIX_BUILDROOT)/build_arm*)
#CROSS_COMPILE       = $(patsubst %g++, %, $(wildcard $(BUILD_ARM)/staging_dir/bin/arm-linux-uclibc*-g++))
#CROSS_COMPILE = /home/irmabot/gumstix/gumstix-oe/tmp/cross/arm-angstrom-linux-gnueabi/bin/
CROSS_COMPILE = /home/babbage/marbotRelease/src/processors/longRangeNavigator/arm/arm-angstrom-linux-gnueabi/bin/
COMMON          = ../../common
SHARED          = Shared
I32 = /usr/include/x86_64-linux-gnu/c++/4.7/bits/


#ifeq ($(strip $(CROSS_COMPILE)),)
#   $(error Unable to detect C++ Cross Compiler)
#endif

vpath %.c  %.cpp $(COMMON) $(SHARED)

CPPFLAGS +=  -I . -I $(COMMON) -I $(SHARED) -I$(I32)
CFLAGS   += -Wall -I$(I32)

ifeq ($(PC), true)
CPPFLAGS += -DPC -m32 
CFLAGS   += -DPC -m32    
CC = g++
CXX = g++

OBJS = longRangeNavigator.o GALRN.o InternalMap.o MandamiFuzzyModel.o     MembershipFunctions_1D.o Utils.o ../../common/configFile/configFile.o 

else                # else
TARGET_ARCH=-Os -march=armv5te -mtune=xscale -Wa,-mcpu=xscale
CC = $(CROSS_COMPILE)g++
CXX = $(CROSS_COMPILE)g++

OBJS = \
   longRangeNavigator.o         \
    GALRN.o                         \
    InternalMap.o                   \
    MandamiFuzzyModel.o         \
    MembershipFunctions_1D.o    \
    Utils.o                         \
    ../../common/configFile/configFile.o


endif               # endif 

all: longRangeNavigator

longRangeNavigator: $(OBJS)

clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions longRangeNavigator

depend .depend dep:
    @echo "Creating dependencies ..."
    $(CXX) $(CFLAGS) $(CPPFLAGS) -M  *.cpp  > .depend

FORCE:

.PHONY: FORCE

PREPROCESS.c = $(CXX) $(CPPFLAGS) $(TARGET_ARCH) -E -Wp,-C,-dD,-dI

%.pp : %.c  FORCE
    $(PREPROCESS.c) $< > $@

ifeq ($(strip $(filter clean, $(MAKECMDGOALS))),)
-include .depend
endif

我的问题是我在amd64机器上编译32位代码。 这是输出

Creating dependencies ...
g++ -Wall -I/usr/include/x86_64-linux-gnu/c++/4.7/bits/ -DPC -m32 -I . -I ../../common -I Shared -I/usr/include/x86_64-linux-gnu/c++/4.7/bits/ -DPC -m32  -M  *.cpp  > .depend
g++  -I . -I ../../common -I Shared -I/usr/include/x86_64-linux-gnu/c++/4.7/bits/ -DPC -m32   -c -o longRangeNavigator.o longRangeNavigator.cpp
g++  -I . -I ../../common -I Shared -I/usr/include/x86_64-linux-gnu/c++/4.7/bits/ -DPC -m32   -c -o GALRN.o GALRN.cpp
g++  -I . -I ../../common -I Shared -I/usr/include/x86_64-linux-gnu/c++/4.7/bits/ -DPC -m32   -c -o InternalMap.o InternalMap.cpp
g++  -I . -I ../../common -I Shared -I/usr/include/x86_64-linux-gnu/c++/4.7/bits/ -DPC -m32   -c -o MandamiFuzzyModel.o MandamiFuzzyModel.cpp
g++  -I . -I ../../common -I Shared -I/usr/include/x86_64-linux-gnu/c++/4.7/bits/ -DPC -m32   -c -o MembershipFunctions_1D.o MembershipFunctions_1D.cpp
g++  -I . -I ../../common -I Shared -I/usr/include/x86_64-linux-gnu/c++/4.7/bits/ -DPC -m32   -c -o Utils.o Utils.cpp
g++   longRangeNavigator.o GALRN.o InternalMap.o MandamiFuzzyModel.o MembershipFunctions_1D.o Utils.o ../../common/configFile/configFile.o   -o longRangeNavigator
/usr/bin/ld: Warning: size of symbol `_ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_ESt4lessISsESaIS2_EED1Ev' changed from 75 in longRangeNavigator.o to 81 in ../../common/configFile/configFile.o
/usr/bin/ld: Warning: size of symbol `_ZNSt4pairIKSsSsED1Ev' changed from 63 in longRangeNavigator.o to 69 in ../../common/configFile/configFile.o
/usr/bin/ld: i386 architecture of input file `longRangeNavigator.o' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `GALRN.o' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `InternalMap.o' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `MandamiFuzzyModel.o' is incompatible with i386:x86-64 

所以,问题显然在这里。我在哪里将32位代码与64位链接器连接起来。

g++   longRangeNavigator.o GALRN.o InternalMap.o MandamiFuzzyModel.o MembershipFunctions_1D.o Utils.o ../../common/configFile/configFile.o   -o longRangeNavigator

我完全不了解Makefile niether这个动作的执行情况。 我只想添加-m32参数。

2 个答案:

答案 0 :(得分:0)

如果你有yum或apt,你可以安装gcc 32,并使用它。请使用in或64或32。

答案 1 :(得分:0)

您也需要将-m32传递给链接器。一种方法是将此行添加到Makefile中:

LDFLAGS += -m32

LDFLAGS是一个内置变量,只要implicit rule

调用链接器,其值就会添加到链接器命令中