开发者

Does linking switch order matters?

开发者 https://www.devze.com 2023-04-03 01:45 出处:网络
I tried to put up an example using c++ for accessing Cassandra, and so Using Thrift. Copying the example, I had this strange situation:

I tried to put up an example using c++ for accessing Cassandra, and so Using Thrift.

Copying the example, I had this strange situation:

storm@debian:~/Script/goh-server/src/cassandra$ g++ -I/usr/include/thrift/ -c prova.cpp -o prova.o
storm@debian:~/Script/goh-server/src/cassandra$ g++ -I/usr/include/thrift/ -c cassandra_constants.cpp -o cassandra_constants.o
storm@debian:~/Script/goh-server/src/cassandra$ g++ -I/usr/include/thrift/ -c cassand开发者_运维问答ra_types.cpp -o cassandra_types.o
storm@debian:~/Script/goh-server/src/cassandra$ g++ -I/usr/include/thrift/ -c Cassandra.cpp -o Cassandra.o
g++storm@debian:~/Script/goh-server/src/cassandra$ g++ -lthrift *.o -o prova
Cassandra.o: In function `org::apache::cassandra::CassandraClient::recv_login()':
Cassandra.cpp:(.text+0x12d2c): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'
Cassandra.o: In function `org::apache::cassandra::CassandraClient::recv_set_keyspace()':
Cassandra.cpp:(.text+0x1339c): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'
Cassandra.o: In function `org::apache::cassandra::CassandraClient::recv_get(org::apache::cassandra::ColumnOrSuperColumn&)':
Cassandra.cpp:(.text+0x13a0b): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'
Cassandra.o: In function `org::apache::cassandra::CassandraClient::recv_get_slice(std::vector<org::apache::cassandra::ColumnOrSuperColumn, std::allocator<org::apache::cassandra::ColumnOrSuperColumn> >&)':
Cassandra.cpp:(.text+0x142db): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'
Cassandra.o: In function `org::apache::cassandra::CassandraClient::recv_get_count()':
Cassandra.cpp:(.text+0x14b40): undefined reference to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)'
Cassandra.o:Cassandra.cpp:(.text+0x153bd): more undefined references to `apache::thrift::TApplicationException::read(apache::thrift::protocol::TProtocol*)' follow
Cassandra.o: In function `org::apache::cassandra::CassandraProcessor::process(boost::shared_ptr<apache::thrift::protocol::TProtocol>, boost::shared_ptr<apache::thrift::protocol::TProtocol>, void*)':
Cassandra.cpp:(.text+0x21511): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'
Cassandra.o: In function `org::apache::cassandra::CassandraProcessor::process_fn(apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, int, void*)':
Cassandra.cpp:(.text+0x21882): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'
Cassandra.o: In function `org::apache::cassandra::CassandraProcessor::process_login(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)':
Cassandra.cpp:(.text+0x21fa8): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'
Cassandra.o: In function `org::apache::cassandra::CassandraProcessor::process_set_keyspace(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)':
Cassandra.cpp:(.text+0x2291e): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'
Cassandra.o: In function `org::apache::cassandra::CassandraProcessor::process_get(int, apache::thrift::protocol::TProtocol*, apache::thrift::protocol::TProtocol*, void*)':
Cassandra.cpp:(.text+0x233b9): undefined reference to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const'
Cassandra.o:Cassandra.cpp:(.text+0x23e16): more undefined references to `apache::thrift::TApplicationException::write(apache::thrift::protocol::TProtocol*) const' follow
prova.o: In function `main':
prova.cpp:(.text+0x6e): undefined reference to `apache::thrift::transport::TSocket::TSocket(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)'
prova.o: In function `apache::thrift::transport::TFramedTransport::TFramedTransport(boost::shared_ptr<apache::thrift::transport::TTransport>)':
prova.cpp:(.text._ZN6apache6thrift9transport16TFramedTransportC1EN5boost10shared_ptrINS1_10TTransportEEE[apache::thrift::transport::TFramedTransport::TFramedTransport(boost::shared_ptr<apache::thrift::transport::TTransport>)]+0x26): undefined reference to `vtable for apache::thrift::transport::TFramedTransport'
collect2: ld returned 1 exit status
storm@debian:~/Script/goh-server/src/cassandra$ ls
cassandra_constants.cpp  cassandra_constants.o  Cassandra.h  cassandra_types.cpp  cassandra_types.o  prova.o
cassandra_constants.h    Cassandra.cpp          Cassandra.o  cassandra_types.h    prova.cpp

Then, with some Voodoo I tried to move the -l switch at the end of the linking order, and magically ...

storm@debian:~/Script/goh-server/src/cassandra$ g++ *.o -o prova -lthrift
storm@debian:~/Script/goh-server/src/cassandra$ 

On the Thrift documentation, the -l switch is put in the beginning, and in fact automake DOES put it before the '*.o's and -o switch.

What's wrong with it ?

Edit:

In fact is not true that automake put -l flags in the beginning. It does put them in the end in the linking stage. Still: why does the order matter ?


It matters. -llibrary must follow everything that references the library.

If you have circular references between static libraries, you end up with -llibrary twice.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号