I'm currently porting an app on MVS using the USS interface. I'm facing an issue compiling (using c++ compiler) the following program:
#define _XOPEN_SOURCE_EXTENDED 1
#define _OE_SOCKETS
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main() {
struct in_addr add;
int sd = socket(AF_INET, SOCK_STREAM, 0);
inet_ntoa(add);
return 0;
}
IBM docs states that the one who want to use sockets functions should define _OE_SOCKETS (and _XOPEN_SOURCE_EXTENDED if it's C++). But I'm having undefined symbol socket:
$> c++ test.cpp
"./test.cpp", line 10.12: CCN5274 (S) The name lookup for "socket" did not find a declaration.
CCN0793(I) Compilation failed for file ./test.cpp. Object file not created.
FSUM3065 The COMPILE step ended with return code 12.
FSUM3017 Could not compile test.cpp. Correct the errors and try again.
A bit of investigation make me think that I have a corrupted sys/socket.h header file, indeed here is an extract of this file:
690: #ifndef _OE_SOCKETS /* must be __UU */
...
732: int socket (int, int, int);
...
780: #endif /* ifndef _OE_SOCKETS */
I feel like the #ifndef _OE_SOCKETS should be an #ifdef _OE_SOCKETS.
Can anyone confirm that to me? thanks.
Last, uname gives on the box I'm using:
$> uname -a
OS/390 S0W1 20.00 03 2094
Me again, just in case this would be useful to someone else.
I misread the doc. If your using C compiler define _OE_SOCKETS but if your using a C++ compiler then define _XOPEN_SOURCE_EXTENDED but not both!
Related
The Question
Programming Arduino is something new to me - I've included what I believe is relevant, though please comment if more code/info is needed.
I'm creating a sketch that uses the ArduinoHttpClient library installed via the IDE's 'Manage Libraries' option.
Yesterday all was well - sketch compiles.
Today I get the error below. Nothing changed between yesterday and today that I can tell.
I have tried the code on other machines - 2 work, 1 doesn't and I cannot tell what is wrong and don't fully understand the actual error.
Can anybody explain a) what the error means and b) what i might be able to do to resolve it?
Code pieces
In file included from
/Users/me/Documents/Arduino/libraries/ArduinoHttpClient/src/ArduinoHttpClient.h:8:0,
from
/Users/me/Documents/Proj/network-comms/ard-mkr-wifi-1010/box_register.h:1,
from
/Users/me/Documents/Proj/network-comms/ard-mkr-wifi-1010/ard-mkr-wifi-1010.ino:11:
/Users/me/Documents/Arduino/libraries/ArduinoHttpClient/src/HttpClient.h:12:1:
error: expected ',' or ';' before 'static' static const int
HTTP_SUCCESS =0; ^~~~~~ exit status 1 Error compiling for board
Arduino MKR WiFi 1010.
The ArduinoHttpClient.h file is as installed and unchanged:
// Library to simplify HTTP fetching on Arduino
// (c) Copyright Arduino. 2016
// Released under Apache License, version 2.0
#ifndef ArduinoHttpClient_h
#define ArduinoHttpClient_h
#include "HttpClient.h"
#include "WebSocketClient.h"
#include "URLEncoder.h"
#endif
box_register.h at line one just includes the lib
#include <ArduinoHttpClient.h>
HttpClient.h from the Arduino lib is as - includes the line being reported:
// Class to simplify HTTP fetching on Arduino
// (c) Copyright MCQN Ltd. 2010-2012
// Released under Apache License, version 2.0
#ifndef HttpClient_h
#define HttpClient_h
#include <Arduino.h>
#include <IPAddress.h>
#include "Client.h"
static const int HTTP_SUCCESS =0; /// <------ LINE 11
// The end of the headers has been reached. This consumes the '\n'
// Could not connect to the server
static const int HTTP_ERROR_CONNECTION_FAILED =-1;
// This call was made when the HttpClient class wasn't expecting it
// to be called. Usually indicates your code is using the class
// incorrectly
static const int HTTP_ERROR_API =-2;
// Spent too long waiting for a reply
ard-mkr-wifi-1010.ino showing line including box_register
// va_start, va_end
#include <stdarg.h>
#include <WiFiNINA.h>
#include <PubSubClient.h>
#include <RTCZero.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include "./arduino_secrets.h"
#include "./box_register.h" // <----- HERE
#include "./ntp.h"
I have a small snipped of code, which just produces a function to get the current directory for either Windows or Linux platform:
#include <stdio.h> /* defines FILENAME_MAX */
#include <string>
#ifdef WINDOWS
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
std::string getcwd(){
char mCurrentPath[FILENAME_MAX];
GetCurrentDir(mCurrentPath, sizeof(mCurrentPath));
return *(new std::string (mCurrentPath));
}
This is all great and working; however, I'd like to make the getcwd() function inside the namespace, fUtils, hence I did this:
#include <stdio.h> /* defines FILENAME_MAX */
#include <string>
#ifdef WINDOWS
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
namespace fUtils{
std::string getcwd(){
char mCurrentPath[FILENAME_MAX];
GetCurrentDir(mCurrentPath, sizeof(mCurrentPath));
return *(new std::string (mCurrentPath));
}
}
But this gives an error in VSCode which says:
no matching function for call to 'getcwd'
What mistake am I making in this? If this isn't how I put the function to the namespace fUtils, then how should I put it into the namespace?
Your fUtils::getcwd() function is attempting to call itself when the GetCurrentDir macro is evaluated (to getcwd), and this results in a function that expects no argument but is being given two arguments.
To resolve this, add the global namespace operator (::) in the definitions for GetCurrentDir, as follows:
#ifdef WINDOWS
#include <direct.h>
#define GetCurrentDir ::_getcwd
#else
#include <unistd.h>
#define GetCurrentDir ::getcwd
#endif
Then, in your function body, it is clear to the compiler that your aren't looking for a 'recursive' (and invalid) call.
Use of macros in such context is invitation to problems in future.
Just wrap those functions with own API and all problems will be resolved.
Header file:
#include <string>
namepsace fUtils {
std::string getcwd();
}
Then you can have platform specific cpp files, Windows:
namepsace fUtils {
std::string getcwd() {
char mCurrentPath[FILENAME_MAX];
::_getcwd(mCurrentPath, sizeof(mCurrentPath));
return {mCurrentPath};
}
}
Mac version is obvious.
You also can use this macros inside single cpp file and this way contain them there if you do not what to do larger clean up.
Side notes:
there is boost::filesystem which has such api also use of boost::filesystem::path is quite handy
C++17 introduces std::filesystem, but it is not well supported yet (for example MacOS)
if you wrap this functionality in classes you will open your way for better testing (mocks).
I am working on the communication between a raspberry pi and a kestrel plate (from procerus technologies). Now, I need to receive information from the packages of the kestrel, for this I am using an old code used in a Gumstix. At the time of compiling it gives me the error of the title ("u8" was not declared in this scope). The error is present in several files. For example
I suppose the error is related to the Linux version
#include "dllsetup.h"
#include "type.h"
#include <vector>
#include <linux/types.h>
#include <asm/types.h>
#include <sys/types.h>
#ifndef LINUX
EXTERN_LINK template class DYNAMIC_LINK std::vector<u8>;
#endif
//! Packet Data Type defines for easy writing of code.
typedef std::vector<u8> PacketData;
typedef std::vector<u8>::iterator PacketDataIter;
u8 isn't in the standard but uint8_t is (included in stdint.h and cstdint). Check your includes, verify that you defined u8 somewhere.
I'm looking at the <linux/types.h> kernel header, and I can't find u8. There is a __u8 pulled in via <asm/types.h>, through two more layers of inclusion.
If I compile
#include <linux/types.h>
u8 u;
on Ubuntu 18 with gcc-7.3.0, it suggests this.
test.c:2:1: error: unknown type name ‘u8’; did you mean ‘__u8’?
u8 u;
^~
__u8
I am attempting to create a TCP server using boost.asio and following the examples you use co_spawn to start the listener function in a new thread.
When I try to use boost::asio::co_spawn Microsoft Visual Studios tells me it is undefined, I have included all files the boost example does.
TcpServer.h
#include <iostream>
#include <string>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/asio/write.hpp>
#include <boost/asio/coroutine.hpp>
using namespace boost::asio;
class TcpServer
{
public:
TcpServer(int port);
~TcpServer();
private:
};
TcpServer.cpp
#include "TcpServer.h"
/*
Create a TcpServer on a given port
*/
TcpServer::TcpServer(int port)
{
io_context ioCtx(1);
/* E0020 identifier "co_spawn" is undefined */
co_spawn();
}
TcpServer::~TcpServer()
{
}
The above code tells me that co_spawn is undefined, I have searched other name spaces and checked for alternative functions and there is none. I thought maybe it was outdated documentation but the boost.asio reference for version 1.70.1 still lists co_spawn as a free function. See here
I am using
Boost: 1.70.1
Microsoft Visual Studio 2017: v15.9.7
boost.asio has preprocessor code to detect the capabilities of the compiler and only turn on coroutine support if the compiler supports it.
For MSVC, I think you will need to add the compiler flag /await to the compiler command line option list.
reference: https://learn.microsoft.com/en-us/cpp/build/reference/await-enable-coroutine-support?view=vs-2019
I am a beginner to cuda, c++ and I am trying to move openssl sha1 cpu code to cuda c,but I ran into a weired problem.
here is the minimum code that can reproduce the problem.
There are three files in this vs2015 cuda9.0 project. They are main.cpp ,sha1.cu and sha1.h
//main.cpp
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "openssl\sha.h"
int main()
{
SHA_CTX ctx;
SHA1_Init(&ctx);
return 0;
}
//sha1.h
#ifndef SHA1_H
#define SHA1_H
#include <stdint.h>
#include <cuda_runtime.h>
namespace cudatest {
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
uint32_t state[5];
uint32_t count[2];
unsigned char buffer[64];
} SHA1_CTX;
#define SHA_CTX SHA1_CTX
#define SHA_DIGEST_LENGTH 20
__device__ void SHA1_Init(SHA1_CTX * context);
#ifdef __cplusplus
}
#endif
}
#endif /* SHA1_H */
//sha1.cu
#include <cuda_runtime.h>
#include "sha1.h"
namespace cudatest {
__device__ void SHA1_Init(SHA1_CTX * context)
{
}
}
The main.cpp uses C/C++ compiler and sha1.cu uses CUDA C/C++
And I add openssl headers into the AdditionalIncludeDirectories,set directory which contains ssleay32.lib and libeay32.lib to library path,set AdditionalDependencies with ssleay32.lib, libeay32.lib .
Then the project built with no error and no warning. But when I run it
or debug it,I found the function SHA1_Init runs into device code and
the program crashed immediately.
why the compiler linked function SHA1_Init with the cuda device
SHA1_Init implement which has a namespace cudatest wrapped instead
of a ssleay32.lib, libeay32.lib CPU implement?
OK,I found the problem.I shouldn't use extern "C" in a c++ namespace.It make the function visiable to the global namespace. if you define another c SHA1_Init function in a .cpp file ,the linker will complain.But if another SHA1_Init is in a openssl lib,the vs C/C++ linker warnned nothing but linked to the cuda implement.