ld:在编译c ++时找不到架构x86_64的符号 [英] ld: symbol(s) not found for architecture x86_64 when compiling c++

查看:71
本文介绍了ld:在编译c ++时找不到架构x86_64的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个小型的C ++程序,该程序是我从另一个同学那里修改的(允许分配),但是我无法编译代码.

I'm currently writing a small C++ program that I modified from another classmate (which was permitted for the assignment), but I cannot get the code to compile.

#include <chrono>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <utility>
#include <algorithm>

using std::vector;
using std::string;
using std::map;
using std::cout;

int main (int argc, char const *argv[]) {
    int bufferSize = 100;

    auto start = std::chrono::high_resolution_clock::now();

    auto edit = string(argv[1]);
    auto source = string(argv[2]);

    std::ifstream input(source);
    char buffer[bufferSize];
    input.rdbuf()->pubsetbuf(buffer, bufferSize);
    vector<string> remove;

    string line;
    while (std::getline(input, line)) {
        std::stringstream ss(line);
        string item;

        while (std::getline(ss, item, ',')) {
            remove.push_back(item);
        }
    }

    map<string, string> findReplace;
    for (auto value : remove) {
        findReplace.insert(std::pair<string, string>(value, ""));
    }

    vector<string> fileContent;

    std::ifstream input2(edit);
    char buffer2[bufferSize];
    input2.rdbuf()->pubsetbuf(buffer2, bufferSize);

    string line2;
    while(std::getline(input2, line2)) {
        fileContent.push_back(line2);
    }

    for (auto pair : findReplace) {
        std::for_each(fileContent.begin(), fileContent.end(), [&pair] (string &substrate) {
            std::size_t startPos = 0;
            std::size_t matchPos;
            string first = pair.first;
            string second = pair.second;
            while ((matchPos = substrate.find(first, startPos)) != string::npos) {
                substrate.replace(matchPos, first.length(), second);
                startPos = matchPos + first.length();
            }
        });
    }

    std::ofstream output(edit);
    for (auto portion : fileContent) {
        output << portion << std::endl;
    }

    auto end = std::chrono::high_resolution_clock::now();

    std::cout << "Time elapsed: "
    << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
    << "ms";
}

每次我使用...编译(OS X 10.10)

Every time I compile (OS X 10.10) using...

gcc -std=c++11 delete.cpp

我收到

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

仍然在此处和Google上进行搜索,但是如果有人能看到原因,我将非常感激您.(这是我的第一个C ++程序).

Still searching here and google, but if anyone can see a reason for this, I would be greatly indebted to you. (This is my first C++ program).

推荐答案

在编译C ++程序时,您需要使用 g ++ *(而不是 gcc ),以便程序将与适当的库链接.

When compiling C++ programs, you need to use g++* (instead of gcc) so that the program gets linked with the proper libraries.

请注意,您仍然可以使用 gcc ,但是您必须自己手动链接所需的库.

Note that you might still use gcc but then you'd have to link the required libraries yourself manually.

这篇关于ld:在编译c ++时找不到架构x86_64的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆