3

牦牛剃须警报。

尽管我无法显示任何源代码,但我认为通过一篇写得很好的帖子,我可能能够提供足够的信息来获得帮助。我在下面尝试的步骤都是从其他帖子中获得的,现在变得有点循环了。

我在 OS X 上使用以下内容:

MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ which g++
/usr/bin/g++

MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ arch
i386

MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr     
--with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr     
--with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ clang++ --version
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ brew --config
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: edcf1d119c4ca9d79d7147a684b7d74767cbb1f6
Last commit: 6 weeks ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: dual-core 64-bit penryn
OS X: 10.9.5-x86_64
Xcode: N/A
CLT: 6.2.0.0.1.1424975374
Clang: 6.0 build 600
X11: 2.7.7 => /opt/X11
System Ruby: 2.0.0-p481
Perl: /usr/bin/perl
Python: /Library/Frameworks/Python.framework/Versions/2.7/bin/python => /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
Java: 1.6.0_65-b14-468

所以给了我三个文件:

  • 变音器3.cpp
  • Metaphone3ExampleCode.cpp
  • 变音器3.h

我尝试用 g++ 编译:

g++ Metaphone3.cpp

我得到:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
  • gcc 和 clang++ 报告相同。
  • 添加 -m32 没有影响。
  • g++ Metaphone3.cpp -I /usr/local/include没有效果

如果我尝试:

g++ -Wall -c Metaphone3.cpp

这消除了警告,并生成了Metaphone3.oMetaphone

如果我尝试执行:

MacBook-Pro-de-Pyderman:Metaphone3 Pyderman$ ./Metaphone
-bash: ./Metaphone: Malformed Mach-o file

更多研究表明我可能错过了链接步骤。所以:

gcc Metaphone3.o -o Metaphone3

但这让我回到了最初的错误。

然后其他帖子建议删除该-c标志,但正是这个标志使我能够通过错误。所以你可以看到这是如何循环的。正如您现在可能正在收集的那样,我是一名开发人员,但不是 C++ 开发人员,并且来自 Python,编译世界对我来说是一个新世界。任何和所有的帮助表示赞赏

4

3 回答 3

2

metaphone3.cpp 应该被编译成一个 .so - 它是一个库而不是一个应用程序

示例代码仅供参考,不用于编译

如果您制作 metaphone3.so,您需要自己制作一个 c++ 应用程序以链接到它并对其进行测试

于 2015-11-04T06:45:34.763 回答
2

一个有根据的疯狂猜测:mainMetaphone3ExampleCode.cpp. 您需要编译两者,并将生成的对象链接在一起。

尝试

    g++ -c Metaphone3.cpp
    g++ -c Metaphone3ExampleCode.cpp
    g++ -o Methaphone Metaphone3.o Metaphone3ExampleCode.o

或者

    g++ -o Methaphone Metaphone3.cpp Metaphone3ExampleCode.cpp
于 2015-11-03T19:55:35.340 回答
0

万一其他人在谷歌搜索中偶然发现了这一点,由于一个简单的错字,我收到了上面相同的错误:maint()而不是main()

smh

于 2020-10-12T23:22:53.577 回答