C++ Eclipse DOxygen NT Table Server

Looking for some help getting pointed in the right direction.$@# Currently have a Labview program running on our RoboRIO that is running a NT Table client.$@#$@# It is communicating with a Labview program running on a PC via a network cable.$@# Labview program on the PC is running a NT Table server.$@# I would like to write a C++ program to replace the labview code on the PC.$@# C++ would run the NT Table server and communicate with the RIO’s labview NT Table Client.
$@#
Thus far, I have found examples of how to write C++ code that runs on a RIO and communicates with the Driver Station NT Table server running on a PC. I have also been trying the following program that was originally posted by euhlmann to help understand and learn NT Tables but am continuing to get errors during the built process:

#include <iostream>
#include “networktables/NetworkTable.h”
#include <ntcore.h>

using std::shared_ptr;

int main() {

NetworkTable::SetClientMode();
NetworkTable::SetIPAddress("172.22.11.2");
NetworkTable::Initialize();

std::shared_ptr&lt;NetworkTable&gt; table;
table = NetworkTable::GetTable("SmartDashboard");

table-&gt;PutString("ExampleString", "Sample Text");
NetworkTable::Shutdown();

return 0;

}

The error is the following:
error: ‘mutex’ in namespace ‘std’ does not name a type
std::mutex m_mutex;

I have also included the following libraries: MinGW, and WPILib
$@#
Any help would be greatly appreciated.

If it says that “X does not name a type” and you expect to be a type, one tip is to look up that X and see what library it belongs to. In this case, std::mutex is defined in header “mutex”. I’d imagine that adding the following line will clear that error.

#include <mutex>

Thank you microbuns for your help. I added the mutex header and now I am getting the following:
undefined reference to ‘NetworkTable::SetClientMode()’
undefined reference to NetworkTable::SetIPAddress(llvm::StringRef)' undefined reference toNetworkTable::Initialize()’
undefined reference to NetworkTable::GetTable(llvm::StringRef)' undefined reference toNetworkTable::Shutdown()’

Any other suggestions for what I might be missing?

I’m not sure how you’re building your code, but I would check out this thread.

Thank you again microbuns for your continued help and guidance. I am trying to understand the link you provided. I’m using Eclipse C++ Oxygen, can I use CMake to build my code? I am very new to this and again any advice is greatly appreciated.

Did you follow these steps? Particularly the toolchain part. It sounds like you don’t have the network tables library available while building - doing the above should make it available.

When you write C++ source code, Eclipse turns it into a program by operating on your source code with a sequence of programming tools – called the toolchain. Although there may be more than two tools, at a minimum you can bet there will be at least two: a compiler and a linker.

The compiler takes your .cpp text files and makes sure they adhere to “legal” C++ syntax – that is, that they comply with the C++ language rules. It turns each source code file into an object file. These object files are a bunch of executable code fragments, much like a box of jigsaw puzzle pieces are fragments of the completed puzzle. The linker glues all the object files together into a single program.

Your first error, about the mutex, was a compiler error. You added the import <mutex> statement, recompiled and the problem went away.

Your code also has a call the the NetworkTable class’ SetClientMode() method. The compiler understands this because you included the NetworkTable.h header file. The compiler is happy because it is able to find the NetworkTable class declaration (and its SetClientMode() method declaration). It assumes that it will find the class definition for NetworkTable in one of the other object files – either one of the object files that it compiled from source code that you wrote or in some library file that you included. It notes in the object file that there is a reference to NetworkTable::SetClientMode() that is unresolved.

The linker sees this unresolved reference to NetworkTable::SetClientMode() and sets about trying to locate the method’s definition. This linker error is telling you that it tried to find the code for SetClientMode() but could not find it anywhere. This is usually because you have not included the library containing the definition for SetClientMode(). Sometimes it because the version of the library it found is incompatible with the declaration it found in your code.

The solution is to open the properties window for your C++ project in Eclipse. Then, in the C/C++ Build --> Settings panel, in the Tool Settings tab, look for the linker down the left side. Click on it’s Libraries item. To its right you should see a “Libraries (-l)” section up top and a “Library search path (-L)” below it. You need to ensure your the NetworkTables library is listed up top and the path to that library file is listed in the bottom.

Thank you again, microbuns. I did follow the steps you suggested so thank you. And thank you BrianK, I greatly appreciate all of the clarification on the different steps when writing a C++ code. I believe I have now successfully set up the path to the library (the location of the networktables.h file) but have not yet succeeded with the actual library (the ‘-l’). I’ve tried adding ‘networktables’ but am getting the following error:
‘cannot find -lnetworktables’
Any suggestions? Could I possibly have not downloaded the library correctly or not saved it in the correct location? Thank you for your time and consideration.

The definition for NetworkTable::SetClientMode() is in the ntcore library. In Linux, the name of the file is libntcore.so or libntcore.a – I’m not sure what it is on Windows. However, when entering it in the “Libraries (-l)” you just enter “ntcore” (without the quotes). The “lib” part of the filename is understood, so you omit it here. Try that without putting anything in the bottom section. If it still doesn’t work then the location of the ntcore library file is somewhere unexpected, in which case you can use the bottom section to give the linker the full path to the ntcore library file.

Thank you BrianK for the continued help. I’ve tried everything I can think for including the ntcore library and continuing to get the following error:

c:/mingw/bin/…/lib/gcc/mingw32/6.3.0/…/…/…/…/mingw32/bin/ld.exe: cannot find -lntcore

I have tried using the bottom section to give the linker the full path and nothing seems to work. Could I have the library saved in the wrong location? I’m running out of ideas. Any thoughts or suggestions?

I owe you an apology. I did not look closely enough to see that you were running MinGW. Using Eclipse and Windows 10, I created a MinGW project and got the same error that mutex does not name a type. Googling this error I saw something on Stackflow stating that MinGW hasn’t yet implemented threading support (a mutex being a means of protecting a critical code segment from simultaneous entry by multiple threads). Granted the post was made 4 years ago. I’m not sure how you got past that issue; I didn’t investigate it further.

I typically use Eclipse within a VM running Linux (Ubuntu 16.04 LTS). I’m not sure whether this is a comfort or not but I created an empty C++ project in my Eclipse/Linux setup using the Cross GCC toolchain. In this project I created an empty file names test.cpp. copied/pasted your code (with the mutex import). As I described in a previous post, I added “ntcore” in the top portion of the Libraries item window and “/usr/home/frc/dev/code/lib” (which is where my libntcore.so library file is located) in the bottom section. It both compiled and linked successfully.

Thank you again BrianK, I really appreciate all of your help. I’m not currently comfortable with the Linux system but would like to be if it’s needed to solve my issues. Could you explain using Eclipse within a VM running Linux? (Send any helpful links?) Is it free to install? Again, any guidance is much appreciated.

It’s a little outdated (Ubuntu has updated since this was written), but this is an excellent tutorial on getting Ubuntu running in virtualbox.

From there, installing Eclipse is pretty easy - visit the eclipse website from Ubuntu and download the appropriate version.

Thanks again for the help. I actually cannot use the Linux operating system, I need to use Windows. Is there any other compliers that can be used in place of MinGW? I appreciate any suggestions.

Yes, quite a few. I personally haven’t used very many, only mingw (through Qt) and gcc (through Cygwin). I’ve also heard of visual studio.

I have a really simple C++ code for NT table client available at:
https://github.com/chaoticmachinery/3534/tree/master/networktables_cpp

Download client3.cpp and go.sh.

go.sh is used to compile it.

CM