Query on ACE framework - c++

Of late, I am facing a problem with a code snippet which doesn't return expected values and this is causing an application to fail.
The code is built on Redhat linux 7.1 using the following command -
g++ ace-test.cpp -I<path-to-ace-6.2-root> -L<path-to-ace-6.2-root>/ace/Linux -g -lACE
The code snippet being built is pasted below -
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "ace/MEM_Addr.h"
#include <iostream>
using namespace std;
int main(int argc, char* []) {
ACE_MEM_Addr addr ;
cout << "ACE_MEM_Addr::addr.get_host_name() " << addr.get_host_name() << endl ;
}
On execution, the code prints the following line
ACE_MEM_Addr::addr.get_host_name() **unknown**
on a system running linux which was recently patched.
On a different system which was not patched, the same code returns the correct hostname.
I am trying to figure out which patch caused this problem, but couldn't make much progress.
If someone can please extend a bit of help, would greatly appreciate it.
If required, I can share the list of patches which were applied.

Finally managed to find the culprit.
Here are the entries in /etc/nsswitch.conf:
hosts: files dns - (On the host without patches)
versus
hosts: files dns myhostname - (On the host which was patched)
Removal of the myhostname entry in the latter fixed the problem.
Associated RHEL knowledge base entry -
https://access.redhat.com/solutions/2766251
Thanks a bunch for all the help !

Related

Failed to connect to Redis (using redis-plus-plus)

So I installed Redis in OpenSuse 15.0 and everything was working well. I was using redis-cli for checking the communication with redis server and it was ok.
I wanted to use redis-plus-plus as I'm coding in C++. Installation was succesfully as it passed all tests.
But then I created my own script (inside general redis-plus-plus folder) with the following code:
#include <sw/redis++/redis++.h>
#include <iostream>
#include <unordered_set>
using namespace sw::redis;
int main()
{
// Create an Redis object, which is movable but NOT copyable.
auto redis = Redis("tcp://127.0.0.1:6379");
redis.set("key", "val");
}
It's a very simple code, just to check that connection was succesfully.
And I was compiling it as follows:
/usr/bin/g++-10 -std=c++17 -o main main.cpp /home/user/redis-plus-plus/test/libredis++.a /home/user/hiredis/build/libhiredis_static.a -pthread
Compilation was ok, but when I execute the ./main I'm getting the following error:
terminate called after throwing an instance of 'sw::redis::Error'
what(): unknown error code: Failed to connect to Redis:
Abortado (`core' generado)
And I have another window with the server running, so I don't know why I can't connect with Redis server and I don't know what else can I try... The problem is with the line
redis.set("key", "val");
because if I remove this line I have no error. Any help will be deeply apreciated, thanks!
UPDATE: The problem above was solved, now I'm facing something similar. I'm trying to implement two more lines:
#include <sw/redis++/redis++.h>
#include <iostream>
using namespace sw::redis;
int main()
{
auto redis = Redis("tcp://127.0.0.1:6379");
redis.set("key", "new_val270622");
auto redis_cluster = RedisCluster("tcp://127.0.0.1:16379");
redis_cluster.set("key", "new_val");
}
And I'm getting this error:
CLUSTERDOWN The cluster is down
If I do
ss -tulpn
I get the following ports:
In redis.config I have made the following changes:
cluster-enabled yes
cluster-config-file nodes-16379.conf
cluster-require-full-coverage yes
And I also used:
redis-cli --cluster fix 127.0.0.1:6379
What am I doing wrong? Thank you so much!!!!

How to integrate MySQL with codeblocks IDE

I have been searching solution for this problem whole day.Any help would make me grateful. I am using Code::blocks IDE 16.01. I want to connect from my IDE to my MySQL database server. I have tried a lot of options but yet to succeed. I have my MYSQL INSTALLER setup already and have downloaded the mysql connector and mysql server. I am gonna show you the code and the way i have already tried.
This is my simple code
#include <iostream>
#include <windows.h>
#include <mysql.h>
using namespace std;
int main()
{
MYSQL* conn;
conn = mysql_init(NULL);
if (mysql_real_connect(conn,"localhost","root","","test",0,NULL,0) !=0)
{
cout << "Succesfully Connected to MySQL database xxxx" << endl;
}
mysql_close(conn);
return 0;
}
I have my MySQL setup in C drive and I have linked that as below
After doing all the work I have been shown the following errors
Please someone help me. Thanks in advance. Please feel free to ask If you guyz need anything to know.
In third step of your CodeBlocks setup you must specify the lib path (and not the include path), as below:
C:\Program Files\MySQL\MySQL Server 8.0\lib .
Then rebuilds your application.

No output displayed when a pointer is defined;

#include <iostream>
using namespace std;
int main()
{
int val = 8;
int *point = &val;
cout << val << *point << endl;
}
I wrote a fairly straightforward program to print out the value of a variable first by using the variable name then by using a pointer to the variable. For some unknown reason though, no output is printed to the console.
However, if I run the same code line by line in the debugger, I get the expected output (88).
Since this problem is likely specific to me, I'll add that I'm using Eclipse Kepler with the MinGW compiler on a 64 bit system. Any help on how I can solve this problem and get pointers to function normally would be highly appreicated.
I found your answer here
and since your code and debugger is correct - this is what you the post recommends that you do:
[1] Uninstall
- Removed all traces of Eclipse (64-bit).
- Removed all traces of MinGW (and/or Cygwin).
- Removed all traces of Java (SDK and JRE).
[2] Restart PC
[3] Install
- Installed latest Java JDK (includes the JRE) 32-bit.
- Installed Eclipse IDE (Java Edition) 32-bit.
- Installed MinGW (with Msys).
- Installed the necessary CDT tools from within Eclipse.
However, as an avid Xcode/Jetbrains user I would recommend that you check your settings first because those are the funnest to debug.
Should work this way:
add stdafx.h
return 0 at termination

CUDA nvlink warning : SM Arch ('sm_35') not found

yesterday installed cuda-6.5 to my ubunutu14.04. I followed the steps stated in cuda's getting started guide. Checked for System requirements and mine was OK. Did pre-installations, uninstalled previously installed cuda, and installed package manager installation. All these steps were successfully performed. I skipped steps runfile installation and croos-build environment fro arm. In [post-installation actions][2] step, added
export PATH=/usr/local/cuda-6.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-6.5/lib64:$LD_LIBRARY_PATH
these lines to .profile file. I upgraded my driver to the latest available driver by running the command sudo apt-get install cuda-drivers. Also verified that I installed correct driver. Rebooted my computer and vaulla cuda-6.5 is build successfully. But when I compile my simpleCuda.cu file
#include <stdio.h>
#include <cuda.h>
#include<iostream>
#include <thrust/device_vector.h>
#include <thrust/logical.h>
#include <thrust/functional.h>
#include <cassert>
#include <cublas_v2.h>
using namespace std;
int main(){
float* dev,host;
cudaError_t stat = cudaMalloc((void**)&dev,10*sizeof(float));
cout << "stat " << stat << endl;
return 0;
}
with nvcc -arch=sm_35 -rdc=true -lcublas -lcublas_device -lcudadevrt -o my simpleCuda.cu compile parameters set I got a warning message
nvlink warning : SM Arch ('sm_35') not found in '/usr/local/cuda-6.5/bin/../targets/x86_64-linux/lib/libcublas_device.a:maxwell_sgemm.asm.o'
nvlink warning : SM Arch ('sm_35') not found in '/usr/local/cuda-6.5/bin/../targets/x86_64-linux/lib/libcublas_device.a:maxwell_sm50_sgemm.o'
`
. In this link I see that it can be ignored. But I don't want to ignore this message. I compiled this simpleCuda.cu with the same compilation parameters set on different computer with cuda-5.5 compilation tool. It does not give me any warning message about architecture linking (-arch=sm_35). I want to get rid of this warning message. These compile parameters are not necessary for this particular code I posted, but further I will need them. I appreciate all your help.
This was apparently a toolchain limitation which was rectified in the CUDA 7 production release.
[This answer was assembled from comments to get the question off the unanswered queue for the CUDA tag]

c++ cgi on linux server

I am pretty new to CGI's and wanted to give them a try. Here is my situation:
My website is hosted on a linux server, I have contacted the hosting company and they said as long as I use the cgi-bin folder there is no problem. So I wrote a very short c++ program that just output some text:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello from c++ cgi";
return 0;
}
Since its a linux server (and I am running Windows) I suppose I needed to compile the source in linux so a installed a virtual machine running Ubuntu. I then compiled the source (tested it in Ubuntu) and placed the binary file in the cgi-bin folder. Then I used a simple html anchor to link to it:
T
But when I click the link on my page I get the "500 Internal Server Error" message. I have also tried to rename the binary file to "cgiTest.cgi" and update the link but still the same problem.
Anybody have any idea where my problem lies?
You forgot to output any HTTP headers (the error log entry would give you a hint).
#include <iostream>
using namespace std;
int main()
{
cout << "Content-Type: text/plain" << endl << endl;
cout << "Hello from c++ cgi";
return 0;
}
Thanks for the help, turns out I had to change the permissions and the hosting server is 32bit while I compiled on 64bit Ubuntu. I now compiled on 32bit Ubuntu and voila!, its running. Thanks to all for the help in solving this issue!