Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I link an .o file using g++

Tags:

c++

g++

I am trying to use g++ to compile a .cc file, and I need it to link a .o file.

So I tried:

$g++ -o client -I../ipc -L../messages.o client.cc
/usr/bin/ld: error: ../messages.o: can not read directory: Not a directory

And I have tried:

$g++ -o client -I../ipc -l../messages.o client.cc
/usr/bin/ld: error: cannot find -l../messages.pb.o
$$ ls -l ../messages.o

-rw-r--r-- 1 hap497 hap497 227936 2010-02-03 22:32 ../messages.o

Can you please tell me how to link in a .o file?

Thank you.

like image 590
n179911 Avatar asked Feb 04 '10 22:02

n179911


People also ask

How do I run a .o file?

An object file ( .o ) is not executable. You want to be running ./demo_fully_homomorphic (e.g. the file without extension). Make sure you have execute permissions ( chmod a+x demo_fully_homomorphic ). Show activity on this post.

How are object files linked?

A shared object file holds code and data suitable to be linked in two contexts. First, the link-editor can process it with other relocatable and shared object files to create other object files. Second, the runtime linker combines it with a dynamic executable file and other shared objects to create a process image.

Are .O files cross platform?

No. They are not platform independent.

Is .O a binary file?

It does this by turning the C source code into an object code file, which is a file ending in ".o" which contains the binary version of the source code. Object code is not directly executable, though.


1 Answers

$g++ -o client -I../ipc client.cc ../messages.o
like image 193
t0mm13b Avatar answered Sep 19 '22 13:09

t0mm13b