|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
Member 14968771 wrote: what to ask Mrs Google to help me write a C++ code to
Try: "How to learn C++". Give me about 196,000,000 results
Mircea
|
|
|
|
|
Member 14968771 wrote: is "tokenization" a good search word ?? Fair enough, but that is only the very beginning. A precursor to parsing.
Tokenization is the chopping into atomic pieces of the input text, with no concern for how they are put together. All the tokenizer knows is how to delimit a symbol (token): That a word symbol start with a alphabetic and continues through alphanumerics but ends at the first non-alphanumeric - the tokenizer doesn't know or care whether the word is a variable name, a reserved word or something else. If it finds a digit, it devours digits. If the first non-digit is a math operator or a space, it has found an integer token. If it is a decimal point or an E (and the language permits exponents in literals), the token is a (yet incomplete) float value, and so on. The only language specific thing that the tokenizer needs to know is how to identify the end of a token. Once it has chopped the source code into pieces, its job is done.
Parsing is identifying the structures formed by the tokens. Identifying block, loops, conditional statements etc.
The borderline isn't necessarily razor sharp. Some would say that when the tokenizer finds an integer literal token, it might as well take the the task of converting it to a binary numeric token value, to be handed to the parser. That might be unsuitable in untyped languages where a numeric literal may be treated as a string. After identifying a word symbol, it might search a table of reserved words, possibly delivering it to the parser as a reserved word token. Again, in some languages this is unsuitable (and lots of people would say it goes far beyond a tokenizer's responsibility).
If you want to analyze some input, doing an initial tokenization before starting the actual parsing is a good idea. Most compilers do that.
Curious memory:
One of my fellow students was in his first job after graduation set to identify bacteria in microscope photos. That was done by parsing: They had BNF grammars for different kinds of bacteria, and the image information was parsed according to the various grammars. If the number of parsing errors was too high, the verdict was 'Nope - it surely isn't that kind of bacteria, let me try another one!' Those grammars with a low error count was handed over to a human expert for confirmation, or possibly making a choice between viable alternatives, if two or more grammars gave a low error count. This mechanism took a lot of trivial work off the medical personnel, and the computer could scan far more images for possibly dangerous bacteria than there would be human resources to do. The university lecturer in the Compilers and Compilation course certainly hadn't prepared us for compiling bacteria!
|
|
|
|
|
trønderen wrote: compiling bacteria! Is that making bugs from bacteria, or vice versa?
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
|
I want to create some DLL files for specific calculations and import them into my C# project. Can those calculations (C++ codes in DLL files) be done in the C# application as fast as a native C++ environment?
|
|
|
|
|
As always. It depends. It depends on what the calculations are and how you write the code.
There's no way for anyone to give you a direct answer for this.
|
|
|
|
|
I was reading this turorial on how to use Java in your C++ project, and at one step it says to add the location of jvm.dll to PATH. Well that is fine for developing purpose, but not for a released project. So instead of that I tried the second part, to add it manually to Debug/Release folder and remove the location from PATH, but unfortunately I'm getting the following error:
Error occurred during initialization of VM
Failed setting boot class path.
What I'm I doing wrong, and how to fix the problem?
|
|
|
|
|
|
|
Well, has it worked when you added the location of jvm.dll to PATH?
|
|
|
|
|
Yeah, that was the first thing I tried. I even tried it's Released version (copy in another location .exe and the required .class file) and that was working fine if I had it in PATH, but same problem as soon as I removed it from there and added the dll file.
|
|
|
|
|
You should not do this; Java uses other items in its run-time library. Any client wishing to run your application will need to install Java before they can use it. And it is quite possible that if you install the dll yourself you will be breaching Oracle's licencing conditions.
|
|
|
|
|
I thought that is the problem but then what is the solution for this? Having the user to install Java isn't a problem, but even if it is installed, I still need to add something in Visual Studio to know where to look for jvm.dll as it is the case with <JDK-DIR>/include and <JDK-DIR>/include/win32 , or else it will give me an error with "jvm.dll not found".
|
|
|
|
|
You have to read the documentation about what and where is to be written while installing the Java.
Perhaps you will also need to check the registry to find out where Java installer stores the path you need for your application to work properly.
|
|
|
|
|
If the customer correctly installs the Java runtime then it will set the PATH variable with the correct details. Your code should then run correctly. I have done a test on my system and that is all that is needed as far as I can tell.
The <jdk-dir>/include and <jdk-dir>/include/win32 files are only required to build your application, not to run it. The customer just needs the correct C/C++ libraries installed - Latest supported Visual C++ Redistributable downloads | Microsoft Docs[^].
|
|
|
|
|
For C++ projects, I think in some versions of Visual Studio the 'current directory' is actually the $(SolutionDir) or maybe $(ProjectDir) when you run from the IDE.
Using a search engine[^] you will find that the JVM is loaded with LOAD_WITH_ALTERED_SEARCH_PATH
Have a look here:
Dynamic-Link Library Search Order - Win32 apps | Microsoft Docs[^]
Scroll down to the documentation about LOAD_WITH_ALTERED_SEARCH_PATH
This flag means that the path containing the executable will never be checked. The 'current directory' is checked. Which I believe is $(SolutionDir) or maybe $(ProjectDir) when you launch from Visual Studio.
|
|
|
|
|
I wanted to try Java 1.8.0_202 to test some other stuff, but after changing in PATH the location for jvm.dll for this version, and also in Visual Studio the location for the folders /include,/include/win32, and /jdk1.8.0_202/lib for jvm.lib , now I'm getting that it can't find the class file.
I tried the following (solution name "Article-JNI-1", project name "Example3", class file name "MyTest.class"):
- Leaving the class in "\Article-JNI-1\Exemple3" folder;
- Moving it to "\Article-JNI-1";
- Moving it to "\Article-JNI-1\x64\Debug";
- Changing code to options[0].optionString = "-Djava.class.path=D:\\"; and moving the class there.
In all those situations I'm getting the same thing, the error from line 58:
cerr << "ERROR: class not found !";
While working with jdk-17.0.1 it was working fine when running from Visual Studio. What am I missing/doing wrong?
|
|
|
|
|
This is the code I use to load a class from C++:
JNIEnv* createJVM(
JavaVM* jvm,
std::string strcwd
)
{
JavaVMOption options{};
std::stringstream ssoptions;
ssoptions << "-Djava.class.path=";
ssoptions << strcwd;
std::string stropts = ssoptions.str();
options.optionString = const_cast<char*>(stropts.c_str());
JavaVMInitArgs vm_args;
vm_args.version = JNI_VERSION_1_8;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = false;
vm_args.options = &options;
JNIEnv* env;
jint res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if (res != 0)
{
std::cout << "C++: JNI_CreateJavaVM returned: " << res << std::endl;
}
return env;
}
The caller then uses the env pointer to access the remaining JNI functions.
|
|
|
|
|
I added your function but I have the same result. And so I decided to do a little bit of testing. In Visual Studio I left the locations for jdk1.8.0_202 in properties, but I changed in PATH the location for jvm.dll . IF I'm using the PATH for jdk-17.0.1 it is working fine, but as soon as I change it to jdk1.8.0_202 it doesn't find the class anymore.
|
|
|
|
|
There should be no difference between the two. But Without access to your system it is impossible to guess what might be the problem.
|
|
|
|
|
I just created 2 new VM's (Windows 10 x64), in one I installed Java SE 8 with Visual Studio, and I was getting the same thing, class not found, then I installed Java SE 17 and just like on host, no problem it is running fine.
Then on the second machine I installed Java from oracle ^, which the user would do, and copied the working executable (with no errors) to it (after installing needed redistributable of curse) but I'm getting "jvm.dll" not found error.
|
|
|
|
|
I just installed the 1.8 version of Java and rebuilt my project and it works fine. Have you checked that you are not trying to mix x86 and x64 code? Version 17 is x64 only, but 1.8 offers both. So if you have the x86 version installed that could be the problem.
|
|
|
|
|
Yeah, to be sure there isn't a problem with the installation, I even just uninstalled everything Java related, and reinstalled them. I don't even have a folder in "Program files (x86)", and in x64 I have these only 17 and 1.8 (and what I'm working on right now it is for x64 only anyway):
https://i.ibb.co/X3xcDcf/image.png[^]
When I have in PATH location from 1.8:
https://i.ibb.co/K0vzM4J/image.png[^]
And when I have in PATH location from 17:
https://i.ibb.co/d23HNTv/image.png[^]
It is the project from that tutorial with unmodified files. I even did some Java socket call tests from C++ and they worked fine with 17. That is kinda the main reason I need this Java/C++ combination for, as I already have some systems made in Java that this new project (made in Unreal Engine which is C++) will relay on.
modified 15-Jun-22 15:36pm.
|
|
|
|
|
Make sure that you build the C++ part and the Java part with the same version of Java, they may not be fully compatible across different versions. Also, rather than using pictures to post simple text information, please use copy and paste and add it to your question.
|
|
|
|