tags:

views:

225

answers:

1

Hi,

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.

+7  A: 
$g++ -o client -I../ipc client.cc ../messages.o

Hope this helps, Best regards, Tom.

tommieb75
This oughtta do it. The OP's problem is that -L specifies a path to search for libraries, and -l specifies a library to find in that path. An object file need only be given as an argument.
Fred Larson
Thank you. I have tried '$g++ -o client -I../ipc client.cc ../messages.o' But it turns out messages.o need libprotobuf.a library. So I tried 'g++ -o client -I../ipc client.cc -l/usr/local/lib/libprotobuf.a -lpthread ../messages.o; And I still get '/usr/bin/ld: ../messages.o: in function ipc::protobuf_AssignDesc_messages_2eproto():ipc/messages.pb.cc:33: error: undefined reference to 'google::protobuf::DescriptorPool::generated_pool()'I appreciate for more ideas?
n179911
Instead of `-l/usr/local/lib/libprotobuf.a`, try just `-lprotobuf`. `/usr/local/lib` is probably in your default path; if not, add it with `-L/usr/local/lib`. The `-l` option adds the 'lib' to the front and '.a' to the end.
Fred Larson