"u8" was not declared in this scope - c++

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

Related

Sudden error compiling code for thr Arduino MKR WiFi 1010

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"

Global function not recognized by CUDA C

I have a very complicated program and i have simplified it in order to make my problem easy to understand: I have a 2 scripts and 1 header: time_analysis.cu, DSMC_kernel_float.cu and DSMC_kernel_float.h;
Here is the time_analysis.cu
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <cutil.h>
#include <stdio.h>
#include <assert.h>
#include <memory.h>
#include <string.h>
#include <time.h>
#include <cuda_gl_interop.h>
#include <cutil_math.h>
#include "math_constants.h"
#include "vector_types.h"
#include "vector_functions.h"
typedef struct {
int seme;
} iniran;
typedef struct{
int jp1;
int jp2;
float kx;
float ky;
float kz;
} stato_struct;
stato_struct* coll_CPU=0;
stato_struct* coll2dev=0;
stato_struct* coll_GPU=0;
#include "DSMC_kernel_float.h"
//==============================================================
int main(void){
int N_thread = 4;
int ind;
coll_CPU[0].jp1= 0;
coll_CPU[1].jp2= 1;
coll_CPU[2].kx= 2;
coll_CPU[3].ky= 3;
coll_CPU[4].kz= 4;
for(ind=0;ind<=5;ind++){
coll2dev[ind]=coll_CPU[ind];
}
coll2dev=(stato_struct*) malloc(N_thread*sizeof(stato_struct));
CUDA_SAFE_CALL(cudaMalloc((void**)&coll_GPU, N_thread*sizeof(stato_struct)));
CUDA_SAFE_CALL(cudaMemcpy(coll_GPU,coll2dev,N_thread*sizeof(stato_struct), cudaMemcpyHostToDevice));
CollisioniGPU<<<4,N_thread>>>(coll_GPU);
CUT_CHECK_ERROR("Esecuzione kernel fallita");
CUDA_SAFE_CALL(cudaMemcpy(coll2dev, coll_GPU, N_thread*sizeof(stato_struct),cudaMemcpyDeviceToHost));
free(coll2dev);
CUDA_SAFE_CALL(cudaFree(coll_GPU));
free(coll_CPU);
return 0;
}
Here is the DSMC_kernel_float.cu
// Kernel della DSMC
#include "DSMC_kernel_float.h"
__global__ void CollisioniGPU(stato_struct *coll_GPU){
coll_GPU[0].vAx=1;
coll_GPU[1].vAy=1;
coll_GPU[2].vAz=1;
coll_GPU[3].tetaAp=1;
coll_GPU[4].phiAp=1;
}
Here is the DSMC_kernel_float.h
__global__ void CollisioniGPU(stato_struct* coll_GPU);
However when i type nvcc -I common/inc -rdc=true time_analysis.cu DSMC_kernel_float.cu in the terminal I get a weird message error and i don't understand why
DSMC_kernel_float.h(1): error: attribute "global" does not apply here
DSMC_kernel_float.h(1): error: incomplete type is not allowed
DSMC_kernel_float.h(1): error: identifier "stato_struct" is undefined
DSMC_kernel_float.h(1): error: identifier "coll_GPU" is undefined
DSMC_kernel_float.cu(4): error: variable "CollisioniGPU" has already been defined
DSMC_kernel_float.cu(4): error: attribute "global" does not apply here
DSMC_kernel_float.cu(4): error: incomplete type is not allowed
DSMC_kernel_float.cu(4): error: expected a ";"
At end of source: warning: parsing restarts here after previous syntax error
8 errors detected in the compilation of "/tmp/tmpxft_00003f1f_00000000-22_DSMC_kernel_float.cpp1.ii".
From what I read in the internet, I believe the error is cause by the struct but i don't understand how i could fix it to make the program work properly; how is possible that global does not apply here if i have other examples where it seems to be just fine?
Note: commom/inc is the folder provided by Nvidia in order to make Cuda compile correctly.
Regarding this statement:
Note: commom/inc is the folder provided by Nvidia in order to make Cuda compile correctly.
That's a mischaracterization. The referenced files (cutil.h and cutil_math.h) and macros (e.g. CUT_CHECK_ERROR) were provided in fairly old CUDA releases (prior to CUDA 5.0) as part of the cuda sample codes that were delivered at that time. They are not required "in order to make Cuda compile correctly." Furthermore, their use should be considered deprecated (refer to the CUDA 5.0 toolkit release notes). And if you are actually using an old toolkit like that, I would suggest upgrading to a newer one.
Regarding the compile issues, as #talonmies has pointed out, the compiler has no way of knowing what the definition of stato_struct is, when compiling any module that does not contain the definition (whether directly or included). This would be the case for your DSMC_kernel_float.cu module, which is where all your compile errors are coming from.
At first glance, it would seem that a sensible fix would be to move the typedef containing the stato_struct definition from your time_analysis.cu file into your header file (DSMC_kernel_float.h) and move the #include statement for that to the top of the time_analysis.cu file, along with your other includes.
However, it appears that your DSMC_kernel_analysis.cu file believes that there are a variety of members of that stato_struct:
__global__ void CollisioniGPU(stato_struct *coll_GPU){
coll_GPU[0].vAx=1;
coll_GPU[1].vAy=1;
coll_GPU[2].vAz=1;
coll_GPU[3].tetaAp=1;
coll_GPU[4].phiAp=1;
}
which are not part of your current definition of stato_struct:
typedef struct{
int jp1;
int jp2;
float kx;
float ky;
float kz;
} stato_struct;
So this is confusing code, and I don't think anyone else can sort that out for you. You will either need two separate struct definitions, with separate names, or else you will need to modify your stato_struct definition to include those members (.vAx, .vAy, .vAz, .tetaAp, .phiAp).
The (mis)handling of this struct definition and the resultant errors have nothing to do with CUDA. This is arising out of the C/C++ language expectations.

Which C/C++ header file defines a BYTE data type?

I'm porting a header with this declaration:
struct tMaterialInfo {
char strName[255]; // the texture name
char strFile [255]; // the texture
BYTE color [3]; // the color of the object
};
The header has the following includes:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fstream>
#include <vector>
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include<gl\glu.h>// Header File For The GLu32 Library
#include <gl\glaux.h>
Where does that BYTE come from?
I'm guessing it's from Windows.
A byte (8 bits).
This type is declared in WinDef.h as follows:
typedef unsigned char BYTE;
If you are programming C for Windows I assume you are using Visual Studio to develop. You can right click on any keyword and select Go To Definition F12 to find where it is defined.
BYTE is defined in WinDef.h
typedef unsigned char BYTE;
Almost certainly from one of the many headers included from windows.h. The Windows SDK has included typedefs for BYTE, WORD, and DWORD since at least Windows 2.0 days (the earliest Windows SDK I recall having).

Compiling C code, does not see a #define'd constant

I am trying to compile a 8hz mp3 encoder - C code in QT Creator.
In a file l3psy.c that starts like this
#include <stdio.h>
#include "types.h"
#include "error.h"
#include "layer3.h"
#include "l3psy.h"
#include "fft.h"
#include "tables.h"
The build step complains about PI being undeclared here
for(i=0;i<BLKSIZE;i++) window[i] = 0.5*(1-cos(2.0*PI*(i-0.5)/BLKSIZE));
But types.h, which is obviously included, starts like this:
#ifndef TYPES_H
#define TYPES_H
#include <stdio.h>
#include <time.h>
#include "portableio.h"
#ifdef PI
#undef PI
#define PI 3.14159265358979
#endif
#define PI4 .78539816339745
#define PI64 .049087385212
therefore, there is no way for PI to be undeclared.
What can be the problem here?
also, aside from that stopper, I also get complains about "implicit declaration of function abort" and "implicit declaration of function exit" and "incompatible implicit declaration of built-in function 'exit'", but, they are standard functions of c, why would it complain?
For the first problem, about PI, see Pascal Cuoq's comment (that's all).
For the problems with implicit declarations being reported, you haven't included the relevant header(s) for those functions. IIRC exit and abort are declared by <stdlib.h. But check it out.
Cheers & hth.,

USS C++ socket programming and _OE_SOCKETS

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!