Skip to content

Link Error : Undefined symbols #7

@mohitmv

Description

@mohitmv

Hi, I compiled following C++ code in linux machine using g++ -c code.cpp -o code.o

#include <iostream>
using namespace std;

int main() {
  cout << "ABC" << endl;
  return 0;
}

Then I converted code.o to code_mac.o using ./objconv -fmacho64 -nu code.o code_mac.o on mac.

Then I tried to build executable in mac using g++ code_mac.o -o code_mac

and I'm getting following error :

  "std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from:
      _main in mohit_1.o
  "std::ios_base::Init::Init()", referenced from:
      _main in mohit_1.o
  "std::ios_base::Init::~Init()", referenced from:
      _main in mohit_1.o
  "std::cout", referenced from:
      _main in mohit_1.o
  "std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
      _main in mohit_1.o
  "std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
      _main in mohit_1.o
  "___mh_execute_header", referenced from:
      _main in mohit_1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What am i missing ?
Doesn't objconv change the standard library (libstdc++) when I converted a linux binary to mac binary ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions