Error: implicit declaration of function `int open(...)' - c++

I am using open function in one of my C++ project on Solaris OS.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
char in_pathname[PATH_MAX];
int in_fd = -1;
in_fd = ::open(in_pathname, (O_RDWR|O_CREAT|O_TRUNC), 0600);
Using the above line I am getting following compilation error.
implicit declaration of function `int open(...)'
Any idea why its happening.
Note: This source code is very old and I am using gcc version 2.95.3 to compile it.

Some (older) compilers will let you use a function you haven't declared and assume it returns int.
This will happen if you use a file but haven't included the header it is declared in. You seem to be using file's open method, and these docs suggest you therefore need
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

Related

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.

C++, error: '__locale_t' has not been declared

I'm new to C++, I got error: '__locale_t' has not been declared when I included some header files, like #include "ruby.h" , #include <string.h> and so on, but there's no problem for #include <stdio.h>, I'm using eclipse under Linux, the detailed error for #include "ruby.h" and #include <string.h> is:
/usr/include/string.h:548: error: '__locale_t' has not been declared
/usr/include/string.h:549: error: nonnull argument references non-pointer operand (argument 1, operand 3)
/usr/include/string.h:552: error: '__locale_t' has not been declared
/usr/include/string.h:553: error: nonnull argument references non-pointer operand (argument 1, operand 4)
The order of the include is:
#include "Abc.h"
#include <string.h>
#include "ruby.h"
#include <stdio.h>
Where Abc is the class name.
This is the Abc class, nothing added except the include:
#include "Abc.h"
#include <stdio.h>
#include <string.h>
#include "ruby.h"
#include "ose_gw.h"
namespace a {
Abc::Abc() {
// TODO Auto-generated constructor stub
}
Abc::~Abc() {
// TODO Auto-generated destructor stub
}
} /* namespace a */
Try compiling with:
g++ -D__USE_XOPEN2K8 ...
(see also https://sourceware.org/bugzilla/show_bug.cgi?id=10456 which mentions that xlocale.h is only included from string.h when __USE_XOPEN2K8 is defined)
This is apparently a known issue, which was logged as a bug but is actually some kind of subtle configuration error.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52922
I'm a Windows guy and this is out of my league, but the answer is in there somewhere (I think).

KEIL error: no instance of overloaded function "std::transform" matches the argument list

I have a problem that does no resurface (even no warnings) in XCode but does allow me to compile in Keil MDK.
void grammar::parse(std::string &_expr) {
std::transform(_expr.begin(), _expr.end(), _expr.begin(), std::tolower);
_expr.erase(std::remove_if(_expr.begin(), _expr.end(), std::isspace), _expr.end());
}
That is what I get
error: #304: no instance of overloaded function "std::transform" matches the argument list
error: #304: no instance of function template "std::remove_if" matches the argument list
Header included:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <stdio.h>
#include <algorithm>
Could you please advise me on where to look? I am surprised that XCode version works as expected...
You include ctype.h, that header declares a function tolower in the global namespace (this is part of the C library, so there are no other namespaces there). Maybe you meant to include cctype. For a given C standard library header X.h, there is a c++ version cX that provides some of the same functionality inside the ::std namespace.

undefined reference to `std::__default_alloc_template<true, 0>::deallocate(void*, unsigned int)'

During linking code on ubuntu I get following error
undefined reference to 'std::__default_alloc_template<true, 0>::deallocate(void*, unsigned int)'
I tried several g++ compilers but nothing changes. The reason I found in previous answers is wrong configuration if includes. Here are includes in the code:
#pragma warning(disable:4786)
#include <stdio.h>
#include <map>
#include <string>
#include <vector>
#include <png.h>
#include <math.h>
#include <ft2build.h>
#include <gd.h>
#include FT_FREETYPE_H
using namespace std;
#ifndef WIN32
#define stricmp strcasecmp
#else
#include <io.h>
#include <fcntl.h>
#endif
Please help to fix those includes?
Your are probably compiling and linking with gcc instead of g++. For compilation, there's not much difference. GCC uses the file extension to guess the real language, but when linking, g++also pulls in the C++ Standard library, which is where allocators are usually defined.

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.,