error C3861 : identifier not found, error C2065: undeclared identifier - namespaces

I'm new to Visual Studio Express 2008. I succeeded in executing the C++ compiler from command line on my single cpp file, after i had to add some path in the %include% to .. .NET\console\Templates\1033 for the stdafx.h definition file (why do i need to do that, i would have thought the installer would put everything i need... ??) and it worked, but now i get the error C3861 for 'printf', 'sprintf', 'fopen'... and also error C2065 for 'FILE', 'fpIndex', 'fpData'... Both errors seem to be associated with a namespace problem! I have no idea on what to do about a namespace, when i tried the command suggested for these errors on MS website using namespace std; i got one more error saying "a namespace with this name does not exist" ?
i only have these few includes and the code
#include "stdafx.h"
#include <windows.h>
#include <time.h>
#include <process.h>
#include <stdlib.h>
#include <malloc.h>

You're missing a library you need for those functions. Try adding #include < stdio.h>

Related

nvcc compilation errors with "M_PI" and "or"

When trying to compile this piece of code:
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
void minimal_example(){
int i=2;
if(i==3 or i==4) printf("I want %d!\n",M_PI);
}
using
nvcc -x cu -Xcompiler=/permissive- -dc cuda_nvcc_cl_test.cu -o cuda_nvcc_cl_test.obj
I get the follwing errors (in line 7):
error: expected a ")"
error: identifier "M_PI" is undefined
I am using Windows 10 with Visual Studio's cl.exe (Version 19.16.27031.1 for x64) and CUDA toolkit 10.1.
When replacing cmath with math.h and or with || (alternatively add #include <ciso646>), the errors disappear. However, are there some compiler options or other possibilities so that I can keep the code as is?
Also why did -Xcompiler=/permissive- not help?
There are 2 issues here:
Apparently nvcc includes cmath prior to parsing your code. As discussed in the accepted answer here, if you include cmath and you don't have the define instantiated at that point, you won't get M_PI defined, and subsequent inclusions of cmath won't fix this, due to include guards. A possible workaround for this is to add -D_USE_MATH_DEFINES to your compile command line. This puts the define in place from the start of the compilation process, and M_PI gets defined that way.
Contrary to what I read as correct or standard behavior, the use of or in place of || seems to be conditioned on inclusion of ciso646 (on nvcc on windows/visual studio only. nvcc on linux doesn't seem to need this). Yes, I understand it is not supposed to work that way, but nevertheless it appears to be necessary. This may be an issue with Visual Studio. You can experiment with the /Za switch if you like. (It didn't seem to help when I tried it.)
With CUDA 10.1, on VS2019, when I compile this:
#include <cstdio>
#include <ciso646>
void minimal_example(){
int i=2;
if(i==3 or i==4) printf("I want %f!\n",M_PI);
}
with this command line:
nvcc -x cu -dc test.cu -o test.obj -D_USE_MATH_DEFINES
I get no errors or warnings. Note that I have also changed your printf format specifier from %d to %f to be consistent with the type of M_PI.
If you really don't want to include ciso646, nvcc supports the -include switch to include a file directly from the command line. Therefore I can compile this:
#include <cstdio>
void minimal_example(){
int i=2;
if(i==3 or i==4) printf("I want %f!\n",M_PI);
}
like this:
nvcc -x cu -dc test.cu -o test.obj -D_USE_MATH_DEFINES -include ciso646
with no errors or warnings.

Compiling c code with my_global.h, main function is OK but nothing else [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I can't compile the code when i'm including my_global.h.
This is not supposed to be a main function, since data before is "collected" by code in another c file thar together with this one will be the program (using external variables, which is not in the code yet).
My problem is that I can not compile the code when the function is other than "main". I made a very simple example below, so if i replace "void test() {" with "void main() {" in below example compiling is OK. Keeping "test" but removing #include my_global.h is also OK. But in the final code of course I need my_global.h, so I can't remove it. So the combination of not main and my_global.h gives me this problem.
#include <my_global.h>
#include <mysql.h>
#include <stdlib.h>
#include <stdio.h>
#include "extvar.h"
void test() {
printf("Testing testing\n");
}
I'm compiling with $ gcc -c testa.c -o testa.o 'mysql_config --cflags --libs'.
Error message:
In file included from testa.c:1:0:
/usr/include/mysql/my_global.h:478:21: error: expected identifier or ‘(’ before ‘)’ token
#define test(a) ((a) ? 1 : 0)
^
testa.c:7:6: note: in expansion of macro ‘test’
void test() {
^
I'm very thankful for your help.
You've defined your function to have the same name as a macro defined in mysql/my_global.h. As a result, the name of the function gets macro substitution done on it.
The macro expects an argument, but your function declaration, looks like a function-like macro call that has no arguments, so you get an error.
Define your function to have some name other than test and you should be fine.

getenv() returns null within a MySQL UDF

I'm experiencing a strange issue with the C/C++ function getenv(). The function is used within a MySQL UDF on a Linux system (Linux Mint 16 Cinnamon 64bit). I've set the JAVA_HOME environment variable system-wide by editing the file /etc/environment and it is printed in the shell along with all other variables when using the env command, both as user and root. The code is simple and looks as follows:
char *javaHome;
javaHome = getenv("JAVA_HOME");
if (!javaHome) {
char *m = "Error getting JAVA_HOME variable";
strcpy(message, m);
return 1;
}
The UDF permanently returns the error message in the condition and hence the javaHome variable is always null. I've created another simple C++ program and dropped the cpp file into the MySQL plugin directory where the compiled UDF library resides (/usr/lib/mysql/plugin).
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
char *javaHome = getenv("JAVA_HOME");
cout << javaHome;
return 0;
}
The code returns the value of the variable,i.e.path to the JRE, as expected. The UDF code works fine on my Windows system, but in order to get it to work on Unix systems I had to adapt the code a little and replaced the GetEnvironmentVariableA() function with getenv(). I can't figure out what the problem is. Any pointers would be appreciated.
EDIT: I've tested the result of the "HOME" variable and the output was curiously /etc/mysql/ instead of /root/ as I would have expected. Do UDF's have their own environment or something like that?

Does forward_list supported on xlc

I am porting my code to xlC.
Wondering if forward_list is supported by xlC?
i tried with test program
#include <forward_list>
#include <iostream>
int main()
{
std::forward_list<int> fl;
std::cout<<"Hello";
return 0;
}
Its compiling fine on g++ but giving errror on xlC.
tried following compile line:
xlC forward_list_test.cpp
xlC -D __IBMCPP_TR1__ forward_list_test.cpp
But error is same:
"forward_list_test.cpp", line 1.10: 1540-0836 (S) The #include file is not found.
if its supported do we need to add something extra to compile it?
Note: using xlC 11
forward_list is new with the C++2011 standard, and is not currently supported by XL C/C++ for AIX.
Dwayne Moore
IBM Compilers Product Management and Design

Cython linking to custom C code

I'm trying to use sage to run a basic Cython program that uses a custom C library.
I have three files: hello.h, hello.c, and cpy.spyx.
hello.h:
#include <stdio.h>
void chello();
hello.c:
#include "hello.h"
void chello() {
printf("Hello world\n");
}
cpy.spyx:
#cinclude /home/sage/sage
cdef extern from "/home/sage/sage/hello.h":
void chello()
def pyhello():
chello()
I'm trying to run this in sage using (only) the command:
load "cpy.spyx"
I get the following error:
Import Error /home/sage/sage//temp/... : undefined symbol: chello
This is my first attempt at Cython, so I may have a stupid mistake in my code. An alternate theory is that the .h file is not being copied to the temp directory above.
Thanks
Finally found the solution here:
http://trac.sagemath.org/sage_trac/ticket/1994
There are some apparently otherwise-undocumented directives.
Using the same .c and .h file as above, I used the following .spyx file:
#clang c
#cfile hello.c
#cinclude /home/sage/sage
cdef extern from "/home/sage/sage/hello.h":
void chello()
def pyhello():
chello()
Note the differences between the link and my code above: I didn't include spaces after the #, and I didn't put quotes around the path in the cinclude line. This is a good example of a hello world program for Cython using Sage.
I put all three files (.c, .h, and .spyx) in the /home/sage/sage directory. Then I ran sage and started the program with
load cpy.spyx
No other steps.