链接切换顺序是否重要?

时间:2011-09-07 16:24:58

标签: gcc g++ makefile

我尝试使用c ++来访问Cassandra,然后使用Thrift。

复制这个例子,我遇到了这种奇怪的情况:

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 cassandra_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

然后,在一些Voodoo中,我试图在链接顺序的末尾移动-l开关,并且神奇地......

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

在Thrift文档中,-l开关放在开头,实际上automake DOES把它放在'* .o和-o开关之前。

它出了什么问题?

编辑:

事实上,在开始时,automake put -l标志是不正确的。它确实将它们放在链接阶段。仍然:为什么订单很重要?

1 个答案:

答案 0 :(得分:2)

很重要。 -llibrary必须遵循引用该库的所有内容。

如果静态库之间有循环引用,则最终会使用-llibrary两次。