怎么可能写这个makefile?

时间:2011-11-03 17:18:11

标签: eclipse makefile crypto++

我有这三个命令来编译我的程序:

  1. g ++ -I / usr / include / cryptopp -O0 -g3 -Wall -c -fmessage-length = 0 -MMD -MP -MF“AESBest.d”-MT“AESBest.d”-o“AESBest.o “”AESBest.cpp“
  2. g ++ -I / usr / include / cryptopp -O0 -g3 -Wall -c -fmessage-length = 0 -MMD -MP -MF“main.d”-MT“main.d”-o“main.o “”main.cpp“
  3. g ++ -L / usr / include / cryptopp -o“Crypto”AESBest.o main.o -lcryptopp -lpthread
  4. 考虑到这三个命令,如何创建一个makefile?

    在Eclipse中,我从shell中的程序接收输出,但在我的bash中,当我编译名为“Crypto”的bin文件并启动它时,我的bash shell中没有输出。 为什么呢?

1 个答案:

答案 0 :(得分:2)

这将有效:

all:
  g++ -I/usr/include/cryptopp -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"AESBest.d" -MT"AESBest.d" -o "AESBest.o" "AESBest.cpp"
  g++ -I/usr/include/cryptopp -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "main.cpp"
  g++ -L/usr/include/cryptopp -o "Crypto" AESBest.o main.o -lcryptopp -lpthread

你可以把它分解成这样:

AESBest.o:
  g++ -I/usr/include/cryptopp -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"AESBest.d" -MT"AESBest.d" -o "AESBest.o" "AESBest.cpp"

main.o:
  g++ -I/usr/include/cryptopp -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "main.cpp"

Crypto:
  g++ -L/usr/include/cryptopp -o "Crypto" AESBest.o main.o -lcryptopp -lpthread

然后简化如下:

AESBest.o main.o: %.o : %.cpp
  g++ -I/usr/include/cryptopp -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF$*.d -MT$*.d -o $@ $<

Crypto: AESBest.o main.o
  g++ -L/usr/include/cryptopp -o $@ $^ -lcryptopp -lpthread