Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Microsoft Visual C++ Toolkit 2003: Error: Cannot find "stdio.h"

Posted on 2005-04-24
15
Medium Priority
?
1,837 Views
Last Modified: 2013-12-14
Hello,

I'm working with Java's Native Interface, and I'm trying to compile a very simple C file, with cl.exe (from Microsoft Visual C++ Toolkit 2003). Here's the code:

#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>

JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
    printf("Hello world!\n");
    return;
}

I'm using this at the command line (from the directory with "HelloWorld.h", etc):

cl -I"C:\Program Files\Java\jdk1.5.0_01\include" -I"C:\Program Files\Java\jdk1.5.0_01\include\win32" -LD HelloWorldImp.c -Fehello.dll

I'm ultimately trying to create a Shared Library (called "hello.dll"), but when I run that command, I'm getting the following output:

HelloWorldImp.c
C:\Program Files\Java\jdk1.5.0_01\include\jni.h(21) : fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory

stdio.h exists on my HDD; I've even added the directory that it resides in to my Systems PATH variable (I'm on Windows XP by the way).

Any ideas how I can solve this?

Kind Regards;
Rob
0
Comment
Question by:InteractiveMind
  • 8
  • 6
15 Comments
 
LVL 25

Author Comment

by:InteractiveMind
ID: 13853682
I decided to use <iostream> instead of <stdio.h>, like so:

#include <jni.h>
#include "HelloWorld.h"
#include <iostream>
using namespace std;

JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
    cout << "Hello world!\n";
    return;
}

It was then, that I noticed that the error "'stdio.h': No such file or directory" is referring to line 21 in the jni.h file; as I'm sure you lot have probably already figured.

So, now I'm just lost. :o\

I've changed the code back to the first code which I posted (with use of <stdio.h> ..), and now I'm hoping that someone has an idea of how to solve this?
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 13853823
You may try to add -MD option to your cl command.
0
 
LVL 30

Expert Comment

by:Axter
ID: 13853824
Hi InteractiveMind,
You need to have your path environmental variable setup with the path of the libraries for your compiler.
That path should include the path of the cl.exe file, the path for the *.h header files, and the path for the *.lib library and object files.

I recommend that you use a free IDE, which would automatically setup this for you.
You can download DevC++ which is a free IDE that include the free GNU compiler.

David Maisonave :-)
Cheers!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 16

Expert Comment

by:Peter Kwan
ID: 13853858
Please ignore the above comment.

Is there any VCVARS32.bat file in your <VC++>\bin? If yes, then you try to run the batch in DOS prompt and re-run your cl command again.
0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 13853861
Hi David,

> You can download DevC++ which is a free IDE that include the free GNU compiler
I actually have Dev-C++ already, however, I don't know how to use it to create a Shared Library; could you show me a tutorial, or quickly explain what I need to do?

Cheers.
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 13853864
I mean ignore my first comment. Sorry, Axter, I do not mean to ignore your comment.
0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 13853884
> Is there any VCVARS32.bat file in your <VC++>\bin? If yes, then you try to run the batch in DOS prompt and re-run your cl command again.
Yes, it exists, so I ran it via the Command Prompt, then tried to recompile my code, and now I'm getting a huge list of errors, all basically say:

#: syntax : missing '{' before ':'

Just all referencing different line numbers, and a few different source files.  :o\

Can you explain the Dev-C++ route please?
0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 13853886
That should be:
#: syntax error : missing '{' before ':'
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 13853899
Which file are you getting syntax error from? and the line number?
Can you please post your code for HelloWorld.h?
0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 13853904
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */

#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     HelloWorld
 * Method:    displayHelloWorld
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif
0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 13853918
Before I run: VCVARS32.bat, it shows this error:

HelloWorldImp.c
C:\Program Files\Java\jdk1.5.0_01\include\jni.h(21) : fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory

Which I'm guessing means that an error on line 21 in jni.h is occuring, right?

After I run VCVARS32.bat however, it shows:

HelloWorldImp.c
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(17) : error C2143: syntax error : missing '{' before ':'
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(17) : error C2059: syntax error : ':'
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(17) : error C2143: syntax error : missing '{' before ':'
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(17) : error C2059: syntax error : ':'
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(17) : error C2143: syntax error : missing '{' before ':'
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(17) : error C2059: syntax error : ':'
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(18) : error C2143: syntax error : missing '{' before ':'
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(18) : error C2059: syntax error : ':'
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(18) : error C2143: syntax error : missing '{' before ':'
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(18) : error C2059: syntax error : ':'
C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\cstdio(18) : error C2143: syntax error : missing '{' before ':'
... It actually goes on with very similar errors for 100 lines ...

0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 13853925
Before we continue, is there an easy wat to create a Shared Library with Dev-C++ and their gcc.exe compiler?

Thanks.
0
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 2000 total points
ID: 13854005
Yes, it is easy.

1. You create a DLL project (say HelloWorldProject): File -> New -> Project, Select C project.
2. Add your two files to your project.
3. Click Tools -> Compiler Options -> Directories -> C Includes
4. Add your "C:\Program Files\Java\jdk1.5.0_01\include" and "C:\Program Files\Java\jdk1.5.0_01\include\win32".
5. Click Execute -> Compile. Then your DLL is created.
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 13854012
The third step may also be:

Click Project->Project Options->Directories->Include Directories.
0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 13854024
Thank you very much  :-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question