Apple Mach O Linker错误?

时间:2013-04-22 18:36:57

标签: c++ linker-errors

#include <iostream>
#include <cctype>
#include <string>

using namespace std;




int main()
{

    string text;
    string numbers;
    string characters;
    string spaces;

    getline(cin, text);
    int i;
    for (i=0; i<text.length(); i++)
    {
        if (isalpha(text[i]))
        {
            characters += text[i];
        }
        else if (isdigit(text[i]))
        {
            numbers +=text[i];
        }
        else
        {
            spaces +=text[i];
        }
    }

    cout<<"Numbers in the string: "<<numbers<<endl
    <<"Alphabets in the string: "<<characters<<endl
    <<"Spaces in the string: "<<spaces.length()<<endl<<endl;


    string searchstr;
    string replacestr;
    double n = text.length();

    cout<<"Enter a word to search: "<<endl;

    getline(cin, searchstr);

    cout<<"Enter a replacement word: "<<endl;

    getline (cin, replacestr);

    double position = text.find(searchstr, 0);

    text.replace (position, n, replacestr);

    cout<<"Replaced string is: "<<endl
    <<text<<endl<<endl;



    return 0;
}

无法弄清楚这里发生了什么。是否与使用的图书馆有关?

Error:
Ld "/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Products/Debug/Project 4" normal x86_64
    cd "/Users/andy/Desktop/EECS138/Project 4"
    setenv MACOSX_DEPLOYMENT_TARGET 10.8
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Products/Debug -F/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Products/Debug -filelist "/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Intermediates/Project 4.build/Debug/Project 4.build/Objects-normal/x86_64/Project 4.LinkFileList" -mmacosx-version-min=10.8 -stdlib=libc++ -o "/Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Products/Debug/Project 4"

duplicate symbol _main in:
    /Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Intermediates/Project 4.build/Debug/Project 4.build/Objects-normal/x86_64/main.o
    /Users/andy/Library/Developer/Xcode/DerivedData/Project_4-fgfiiphpwijunsfidkthbsqbxgvb/Build/Intermediates/Project 4.build/Debug/Project 4.build/Objects-normal/x86_64/File.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation

不确定为什么Xcode无法构建/运行程序,它在CodeBlocks中运行得非常好。关于为什么它给我这个错误的任何帮助?

1 个答案:

答案 0 :(得分:0)

根据您的错误,您似乎有一个文件main和另一个文件File 都定义了main()功能。

main()是您的计划的切入点。您无法为程序定义两个不同的函数。