|
The error does not occur during compiling but during linking. It tells you that the final program did not contain the functions in one of the compiled files.
You must also add the source files with those functions to your project. So copy the source file(s) (e.g. funcdefs.cpp) to your directory and add them to the g++ build command.
|
|
|
|
|
Thanks Jochen
I might not have given you enough information. The actual text of the linking error message is:
In function `process(int, char*, ControlData*, char*, char*)':
PROCESS.CPP: (.text+0x788): undefined reference to `readsig(MiscParams*, char*)'
PROCESS.CPP: (.text+0xaac): undefined reference to `sig_save(Signal*, char*)'
PROCESS.CPP: (.text+0xdd4): undefined reference to `display(Signal*, MiscParams*, int)'.............
......etc etc etc
so there are many undefined references to functions from within the function 'process' contained in PROCESS.CPP
however; all these functions are defined in funcdefs.h as follows:
extern int readsig ( MiscParams *misc , char *namelist , int *nsigs ,
Signal ***signals , char *error ) ;
etc etc etc
as I understand it, the various individual *.cpp files are referring to functions that are defined within funcdefs.h shouldn't these definitions be included from this file by the pre processor instruction and therefore be defined references?
Or are you saying that it is the function 'process' in PROCESS.CPP that is calling other undefined references? The very first such call is 'readsig' which is defined in functions.h
Or are you saying that I should just call functions.h functions.cpp?
This is driving me nuts so thanks for your help!
++++++++++EDIT+++++++++++
Jochen - I think I'm beginning to get your drift! The fundefs.h file only contains function prototypes not definitions
modified 4-Mar-15 5:19am.
|
|
|
|
|
I just saw you edited your post and got it. But I will answer anyhow (I had already written this but the CP servers where unavailable for some minutes):
I suggest to read about definitions and declarations in C/C++ because these are often mixed up.
See the first answer of this Stackoverflow thread: http://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration[^]
You have declarations for the functions in your header files. So the sources will compile.
But you don't have definitions for the functions in any of your source files. So the linkage will fail.
You must add the source files containing the definitions. For the readsig function this must be a source file containing:
int readsig ( MiscParams *misc , char *namelist , int *nsigs ,
Signal ***signals , char *error )
{
}
|
|
|
|
|
You must include the library or object modules that contains the actual code of the missing functions. As Jochen already mentioned, these are linker errors, nothing to do with compiling or header files.
|
|
|
|
|
class M
{
//variables
public:
protected:
private:
//functions
public:
M();
~M();
virtual int foo(int);
protected:
private:
M( const M &c );
M& operator=( const M &c );
int i, j;
}; //M
Thanks, any help as always is appreciated.
Cheers
Vaclav
|
|
|
|
|
They are merely section markers, probably put in by some automatic code generator. They allow the developer to easily add properties and functions in the correct places.
|
|
|
|
|
If your question is, why the copy constructor and assignment operator are declared private: This is to prevent the users of the class from copying objects of that type. At least the assignment operator is created atomatically by the compiler, if the designer of the class doesn't explicitely specify one. This default assignment operator simply copies all members. So without the operator you could write
M m1, m2;
m2 = m1;
and it would compile. With this class definition as it is, you will get a compile time error that the operator is not accessible.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Hi All,
I am new to COM. I have a DLL which is written in C. I want to make that DLL a COM dll. SO that i can register it and my application can use it. I tried google a lot. But not finding any satisfactory answer.
Please answer if you have any idea about how to achieve the said.
Thanks in advance
|
|
|
|
|
|
Below is my code tried
class CVersion
void CVersion::ReadValue(BYTE *Buffer, int n_Length, int n_Source)
{
EnterCriticalSection(&m_sReadCritical);
CString tempBuffer((BYTE*)Buffer);
m_svalue = tempBuffer;
m_cData->Data(this);
LeaveCriticalSection(&m_sReadCritical);
}
class CClassVersion
void CClassVersion::Data(CVersion *pcVers)
{
CString m_Value1 = pcVers->m_sValue;
this->SetDlgItemTextA(IDC_EDIT_VAL,m_Value1);
}
//Declared in CVersion header file
protected:
CClassVersion* m_cData;
An Runtime error occurs"Unhandled exception at 0x782ac7da in .exe:0xC0000005:Access violation reading location 0x00000020."
after SetDlgItemText stmt.
Please guide me for the same.
modified 2-Mar-15 1:23am.
|
|
|
|
|
You should step through the code with your debugger to see which variable is invalid. There is nothing obvious in the above code, although it is not easy to understand what it is supposed to be doing.
|
|
|
|
|
Can i use callback function over der?How??????please guide me for the same.Thankyou
|
|
|
|
|
Member 11438021 wrote: Can i use callback function For what reason? You first need to diagnose what is happening in your code to cause the error. When you enter the critical section what are you trying to synchronise with?
[edit]
void CVersion::ReadValue(BYTE *Buffer, int n_Length, int n_Source)
{
EnterCriticalSection(&m_sReadCritical);
CString tempBuffer((BYTE*)Buffer);
m_svalue = tempBuffer;
m_cData->Data(this);
LeaveCriticalSection(&m_sReadCritical);
}
You are setting m_svalue to point to tempBuffer , but as soon as you exit this function that buffer will get released so the pointer is no longer valid. Looking at this code again I cannot see what useful purpose it serves.
[/edit]
|
|
|
|
|
I want to update the text(string) on u/i page.I am sending the message on button click and want to receive the same string on Edit controlBox.
|
|
|
|
|
Then you need to manage the lifetime of the string. If you pass it from one thread to another then you must ensure it is not deleted from its source until the destination has taken a secure copy. In your sample code your destination thread is taking a copy, but only into a temporary location which immeditely gets disposed. Assuming that m_svalue is a string pointer then you just need to allocate a buffer of the required size to it, and copy the message string across. You can then delete it at some later point.
|
|
|
|
|
Can you just give the sample code for the same.Because i tried ,but i am doing a small mistake somewhere.How will i store the string in a buffer so that it can be accessible from another class and use for updating the text.
|
|
|
|
|
Sample code for what? Allocate a memory buffer, copy the string into it, and pass it to the receiver. The receiver can then keep that buffer until it is no longer needed.
|
|
|
|
|
I assume this is a threading problem. The code can probably be called from different threads (that's why you use a Critical Section), but the control text can only be set from the GUI thread.
The easiest way to achieve this is using a timer. So in the ReadValue() fucntion you only put the data into m_svalue. And in the OnTimer() function (which runs in GUI thread) you call Data(). This would of cource mean that you need to store the most recently used CClassVersion object somewhere.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Can i use Handler or callback function,if yes.How???
Guide for the same.Ty.
|
|
|
|
|
How is m_cData initialized?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
m_cData is declared as pointer
|
|
|
|
|
I understand that, but what value are you assigning to it?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
I wrote a DLL with VC6.0. I want to pass a LPCSTR type parameter (file path) to a thread. Here is the code:
DWORD WINAPI ThreadFunc(LPVOID lpParam)
{
char* fileLoct = (char*)lpParam;
MessageBox(NULL, fileLoct, "Message", MB_OK |
MB_ICONINFORMATION);
return 0;
}
void __stdcall StartThread(LPCSTR flt)
{
HANDLE hThread;
hThread = CreateThread(NULL, 0, ThreadFunc,
(void *)flt, 0, NULL);
CloseHandle(hThread);
}
I tested it with MessageBox and found the path was not correct at all. How to correctly pass a LPCSTR type parameter to a thread in DLL?
Thank you.
|
|
|
|
|
What was "not correct" about it?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
MessageBox display is not file path, instead it showed something "s" or "c", "7". this is what I don't understand.
|
|
|
|