|
蓝森林 http://www.lslnet.com 2006年6月6日 10:18
【C++】ld连接错误求助!!
在solaris7下用g++编译连接一个程序,报错如下,偶对c++不熟,哪位大虾给点建议,谢谢!!
好象都是一些标准库,查找不到?
[color=red]makefile文件:[/color]
JREHOME=/usr/j2sdk1.4.1_01/jre
PRTIHOME=/export/home/pRTI1516_V2.1
SRCS = BaseFederateAmbassador.cpp Chat.cpp LogicalTimeDouble.cpp StdAfx.cpp
PRTIINCLUDE = -I${PRTIHOME}/include
PRTILIBDIR = -L${PRTIHOME}/lib -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/3.2
JAVALIBDIR = -L${JREHOME}/lib/sparc -L${JREHOME}/lib/sparc/native_threads -L${JREHOME}/lib/sparc/c
lient
CXXFLAGS = -Wall -fPIC ${PRTI_INCLUDE} ${JAVAINC} -DRTI_USES_STD_FSTREAM \
-D_NO_LONGLONG -DUSE_NAMESPACES -U__STL_HAS_NAMESPACES
CXX = g++
ChatCC: ${SRCS}
$(CXX) ${PRTIINCLUDE} \
${SRCS} \
${PRTILIBDIR} ${JAVALIBDIR} ${CXXFLAGS} \
-lrti1516 -ljava -lhpi -ljvm -lverify -lgcc -o $@
clean:
rm -f *~ ChatCC
librti1516.so在指定的lib目录下已经存在了。
[color=red]错误信息如下:[/color]
Undefined first referenced
symbol in file
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::operator[](unsigned)/var/tmp//ccsysNX8.o
std::basic_ios<wchar_t, std::char_traits<wchar_t>; >;::good() const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::append(std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >; const&)/var/tmp//ccsysNX8.o
std::basic_ios<wchar_t, std::char_traits<wchar_t>; >;::exceptions() const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_ios<wchar_t, std::char_traits<wchar_t>; >;::tie() const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_ios<wchar_t, std::char_traits<wchar_t>; >;::setstate(std::_Ios_Iostate)/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::basic_string[in-charge](std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >; const&)/var/tmp//ccsysNX8.o
std::basic_streambuf<wchar_t, std::char_traits<wchar_t>; >;::sputn(wchar_t const*, int)/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::operator=(wchar_t const*)/var/tmp//ccsysNX8.o
std::char_traits<wchar_t>;::eq(wchar_t const&, wchar_t const&)/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_stringstream<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::~basic_stringstream [in-charge]()/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::basic_string[in-charge](wchar_t const*, unsigned, std::allocator<wchar_t>; const&)/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::resize(unsigned)/var/tmp//ccsysNX8.o
std::basic_streambuf<wchar_t, std::char_traits<wchar_t>; >;::pubsync()/export/home/pRTI1516_V2.1/lib/librti1516.so
std::num_put<wchar_t, std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t>; >; >;::put(std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t>; >;, std::ios_base&, wchar_t, long) const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::num_put<wchar_t, std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t>; >; >;::put(std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t>; >;, std::ios_base&, wchar_t, unsigned long) const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_ostream<wchar_t, std::char_traits<wchar_t>; >;& std::operator<< <wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;(std::basic_ostream<wchar_t, std::char_traits<wchar_t>; >;&, std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >; const&)/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::operator=(std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >; const&)/var/tmp//ccsysNX8.o
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::c_str() const/var/tmp//ccsysNX8.o
std::basic_stringstream<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::basic_stringstream[in-charge](std::_Ios_Openmode)/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::basic_string[in-charge]()/var/tmp//ccsysNX8.o
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::basic_string[in-charge](wchar_t const*, std::allocator<wchar_t>; const&)/var/tmp//ccsysNX8.o
std::char_traits<wchar_t>;::length(wchar_t const*)/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::end() const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::~basic_string [in-charge]()/var/tmp//ccsysNX8.o
std::char_traits<wchar_t>;::assign(wchar_t*, unsigned, wchar_t)/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_stringstream<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::str() const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::char_traits<wchar_t>;::copy(wchar_t*, wchar_t const*, unsigned)/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::assign(wchar_t const*, unsigned)/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::begin() const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_ios<wchar_t, std::char_traits<wchar_t>; >;::fill() const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_string<wchar_t, std::char_traits<wchar_t>;, std::allocator<wchar_t>; >;::length() const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_ios<wchar_t, std::char_traits<wchar_t>; >;::rdbuf() const/export/home/pRTI1516_V2.1/lib/librti1516.so
std::basic_ios<wchar_t, std::char_traits<wchar_t>; >;::_M_check_facet(std::locale::facet const*) const/export/home/pRTI1516_V2.1/lib/librti1516.so
ld: fatal: Symbol referencing errors. No output written to ChatCC
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `ChatCC' |
【C++】ld连接错误求助!!
你的头文件是这样定义的吗?
#include <iostream>;
#include <string>;
using namespace std; |
【C++】ld连接错误求助!!
-->
头文件如下:
#include "StdAfx.h"
#include <iostream>;
#include <sstream>;
#ifdef _WIN32
#include <io.h>;
#include <fcntl.h>;
#endif
#include "BaseFederateAmbassador.h"
#include "LogicalTimeDouble.h"
using namespace std;
using namespace RTI;
程序不是我写的,c++不熟,谢谢老大指导 |
【C++】ld连接错误求助!!
你还是把报错的程序贴出来吧,
如果很大,贴一部分就可以了,我帮你看看。 |
【C++】ld连接错误求助!!
这个是主程序,相关api函数都在librti1516.so中。好象报告的是这个动态库中有很多子程序无法找到,是不是编译动态库的时候有问题?
// Chat.cpp : Defines the entry point for the console application.
//
#include "StdAfx.h"
#include <iostream>;
#include <sstream>;
#include <string>;
#ifdef _WIN32
#include <io.h>;
#include <fcntl.h>;
#endif
#include "BaseFederateAmbassador.h"
#include "LogicalTimeDouble.h"
using namespace std;
using namespace RTI;
class ChatCCFederate : public BaseFederateAmbassador
{
private:
auto_ptr< RTIambassador >; _rtiAmbassador;
InteractionClassHandle _messageId;
ParameterHandle _parameterIdText;
LogicalTimeDoubleFactory _myTimeFactory;
LogicalTimeIntervalFactoryDouble _myIntervalFactory;
public:
ChatCCFederate(int argc, char* argv[])
{
RTIambassadorFactory* rtiAmbassadorFactory = new RTIambassadorFactory();
vector< wstring >; args;
wstring host;
if (argc >; 1) {
string2wstring(host, argv[1]);
} else {
host = L"localhost";
}
args.push_back(wstring(L"crcHost = ").append(host));
args.push_back(L"crcPort = 8989");
_rtiAmbassador = rtiAmbassadorFactory->;createRTIambassador(args);
}
~ChatCCFederate() throw()
{
}
void run()
{
try {
try {
_rtiAmbassador->;createFederationExecution(L"ChatRoom", L"chat.xml");
} catch (FederationExecutionAlreadyExists&) {
}
FederateHandle federateHandle = _rtiAmbassador->;joinFederationExecution(
L"Chat",
L"ChatRoom",
*this,
_myTimeFactory,
_myIntervalFactory);
_messageId = _rtiAmbassador->;getInteractionClassHandle(L"Communication");
_parameterIdText = _rtiAmbassador->;getParameterHandle(_messageId, L"Message");
_rtiAmbassador->;subscribeInteractionClass(_messageId);
_rtiAmbassador->;publishInteractionClass(_messageId);
#ifdef _WIN32
// Make sure that stdin is in text mode. Initialization of the
// Java Virtual Machine (done by pRTI) has a side-effect which
// is to set stdin to binary mode.
_setmode(_fileno(stdin), _O_TEXT);
#endif
cout << "Type messages you want to send. To exit, type . <ENTER>;" << endl;
while (true) {
cout << ">; ";
cout.flush();
char msg[256];
cin.getline(msg, sizeof(msg));
if (!strcmp(msg, ".")) {
break;
}
ParameterHandleValueMap parameters;
parameters[_parameterIdText] = ParameterValue(msg, strlen(msg) + 1);
_rtiAmbassador->;sendInteraction(_messageId, parameters, UserSuppliedTag(0, 0));
}
_rtiAmbassador->;resignFederationExecution(CANCEL_THEN_DELETE_THEN_DIVEST );
try {
_rtiAmbassador->;destroyFederationExecution(L"ChatRoom");
} catch (FederatesCurrentlyJoined) {
}
} catch (RTI::exception& e) {
cout << e.what();
}
}
void receiveInteraction(
InteractionClassHandle const & theInteraction,
std::auto_ptr< ParameterHandleValueMap >; theParameterValues,
UserSuppliedTag const & theUserSuppliedTag,
OrderType const & sentOrder,
TransportationType const & theType)
throw(FederateInternalError, InteractionClassNotSubscribed, InteractionParameterNotRecognized
, InteractionClassNotRecognized)
{
if (theInteraction == _messageId) {
string message;
for (ParameterHandleValueMap::const_iterator i = theParameterValues->;begin(); i != thePar
ameterValues->;end(); ++i) {
ParameterHandle const & handle = i->;first;
ParameterValue const & value = i->;second;
if (handle == _parameterIdText) {
message = string(static_cast< const char* >;(value.data()), value.size());
}
}
cout << message << endl;
}
}
void string2wstring(wstring &dest, const string &src)
{
dest.resize(src.size());
for (string::size_type i = 0; i < src.size(); i++)
dest[i] = static_cast<unsigned char>;(src[i]);
}
};
int main(int argc, char* argv[])
{
try {
ChatCCFederate chatCCFederate(argc, argv);
chatCCFederate.run();
} catch (RTI::RTIinternalError& e) {
cout << L"Exception caught " << e.what() << endl;
}
return 0;
} |
【C++】ld连接错误求助!!
vector< wstring >; args;
你使用了vector,怎么不包含它的头文件呢?
还有wstring你也要找到它的头文件包含起来。 |
【C++】ld连接错误求助!!
-->
能告诉我应该加哪几个头文件?加在什么地方?程序是鬼子写的,对c++,偶是菜鸟,见笑:)
谢谢 lenovo |
【C++】ld连接错误求助!!
-->
#include <vector>;
那个wstring应该不用加了,你再试试吧。
还是找本书看看c++吧。 |
【C++】ld连接错误求助!!
-->
我觉得有点不对劲,你看他编译的结果,.o 都出来了。可能不是这个问题,我怀疑那些要包含的都在 "stdafx.h"里声明了,所以他能编译过去。
他是在连接的时候碰到问题的。 |
【C++】ld连接错误求助!!
-->
这个程序原来是在 windows 上开发的,你肯定它能在 solaris 上编译吗? |
【C++】ld连接错误求助!!
-->
我感觉他的问题出在宽字符集上,可我也没用过,
不清楚该怎么办。 |
【C++】ld连接错误求助!!
-->
是呀,我也晕呀,
#include "StdAfx.h"
这个头文件他怎么也包含进来,
是不是一点都不懂呀。 |
【C++】ld连接错误求助!!
-->
这个软件的原型实在windows下开发的,现在想移植到solaris下,鬼子提供的makefile和部分源代码,我也不敢确认是否能在soalris下编译通过,现在就是在做实验。 |
【C++】ld连接错误求助!!
-->
赞成,错误信息每一条都有 wchar_t。 |
【C++】ld连接错误求助!!
-->
StdAfx.h如下:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__0B6A115A_514D_4122_8241_85CE2F6ACDA7__INCLUDED_)
#define AFX_STDAFX_H__0B6A115A_514D_4122_8241_85CE2F6ACDA7__INCLUDED_
#if _MSC_VER >; 1000
#pragma once
#endif // _MSC_VER >; 1000
#pragma warning(disable : 4786)
#include "RTI/1516.h"
#include "RTI/EncodedLogicalTime.h"
#include "RTI/EncodedLogicalTimeInterval.h"
#include "RTI/RTIambassadorFactory.h"
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__0B6A115A_514D_4122_8241_85CE2F6ACDA7__INCLUDED_)
加了 #include <vector>;
还是不行,是不是哪个库文件没有包含进来?g++的和这些错误相关的库文件是哪个呢?
谢谢各位!! |
【C++】ld连接错误求助!!
偶也不懂了。 :oops:
像那个windows下的头文件,
在unix下是没有的。 |
【C++】ld连接错误求助!!
-->
在google下查了,好象是gcc3.2的bug :( |
【C++】ld连接错误求助!!
装一个gcc3.3呀。 :D |
【C++】ld连接错误求助!!
用gcc3.3.2报告无穷的语法错~~~~
看来gcc的版本差异大啊 |
【C++】ld连接错误求助!!
链接错误无非是找不到实现函数而已,不管是库的还是自己写的 |
| |