10-02-2015 08:55 AM
Hi NI,
I usually find my solutions online but I'm struggling with this one. I've done this in an environment before but can't remember how I did it.
So I'm working on an ethernet comm interface. I have a TCP file where I'm using the NI tcp functions (TCP_DATAREADY, TCP_CONNECT, etc), and I have a telnet.c file where I've created simple send and recieve ethernet commands.
My issue right now is that I want to store the buffer I'm transmitting and the buffer I recieved for future use. Below is what I'm trying to accomplish.
*** memory.h file ****
extern char memTransmitString[256] = {0};
extern char memReadString[256] = {0};
*** telnet.c ***
#include "memory.h"
int SendTelnetCmd( bunch of stuff I need)
{
// This sends the command
error = ReadTelnetData (readBuffer);
}
*** tcp.c ***'
#include "memory.h"
case (event)
{
TCP_DATAREADY:
// code gets what I want to read and I store this string in "readBuffer"
Fmt (memReadString, "%s", readBuffer); // this is where I want to store what I read into memory so I can access this string in multiple files.
break;
}
*** telnet.c ***
ReadTelnetData (char *readBuffer)
{
// I trigger a TCP_DATAREADY event here ^^^^^ this is where I'll make the ethernet read and WANT to store read string into a global that I can access in multiple iles
Fmt (readBuffer, "%s", memReadString; // this wll store the string from memory into my return string for this function.
}
So basically the compiler is gettnig mad that I'm reformatting memReadString (even tho technically I'm not reformatting i'm just transferring it back and forth between readBuffer).
The error I get is Project Link Error: Multiple definitions for symbol memReadString.
Pretty much the same thing for memTransmitString.
Can you help me fix this?
Thanks,
Justin
10-02-2015 10:01 AM
Nevermind...
I fixed it by changing char memReadString[256] = {0}; in memory.h to static char memReadString[256] = {0};
10-06-2015 12:41 AM
Did you test your code allready ? I think this "solution" has one side effect, you didn't thought of. Declaring a variable outside a function body static means that it is local to the compilation unit. A compilation unit is usually one preprocessed c file. So now you will have two different variables called memReadString in your code, one in telnet.c , one in tcp.c. The right solution should be
declare in memory.h
extern char memReadString[ ]
and in one of telnet.c or tcp.c the variable definition
char memReadString[256] = {0};