javac cant find referenced class - javac

I don't seem to be able to understand the problem. I have simple project I put together for educational purposes, but, no matter what, it won't compile. I can't figure out what I'm missing. Below is the makefile:
SHELL := /usr/bin/env bash
JFLAGS = -g -classpath "$(PWD)/src/tld/assignments/;$(PWD)/lib/;$(CLASSPATH)"
JC = javac
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java
CLASSES = src/tld/assignments/StoreDao.java \
src/tld/assignments/Store.java
default: classes
classes: $(CLASSES:.java=.class)
clean: $(RM) *.class
The StoreDao compiles, but the Store, which references StoreDao doesn't, and says:
src/tld/assignments/Store.java:9: cannot find symbol
symbol : class StoreDao
I've tried the classpath with slashes and without, colons, semicolons etc. - no difference.
Special notice, because I know someone will certainly say this. No, I don't want / cannot use Ant or Maven. The point of this assignment is to use GNU Make. (I can do it with Ant or Maven etc, that's not a problem).
Another note, just in case, I looked into similar problems posted to SO - none of them is my case (all the rest of them turned out to be a syntax error or some kind of forgetfulness on the side of the poster, which this is not).
Thank you in advance.

Quite brilliantly, even though javac ignores all conventions in path naming, it's also inconsistent on different OS'es, so, it appears that path separator character on Linux isn't a semicolon - it's a colon.
Of course, the official manual never mentions that, as users are supposed to have prerequisite knowledge before they run the program... sigh

Related

Source env variables from bitbake-made sdk using Fish

When you compile a SDK using bitbake and have to source like :
source /opt/poky/.../environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
It can't be accomplished through fish, which is expected as the export sintaxe is different (i.e. set -x ...). I tried even to add #!/bin/bash on the first line, which also doesn't work. Does anyone knows a good way for it?
Workaround: Nowadays I run a bash inside the fish prompt to be able to compile binaries, which is not the best way but works. Don't let those small things push oyu away from fish :)
#charego mentioned some good ideas, thanks! :)
Fish-bax
So you can run it as:
bax 'source /opt/poky/.../environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi'
The only down side is that the auto completion does not work inside quotes, so one will need to write the whole path to the file. Although it's still better to have a fish running on top of a bash.
Bass
Bass did not worked, as it crashs with: Fatal Python error: Py_Initialize: Unable to get the locale encoding ImportError: No module named 'encodings'
Foreign-env
Foreign-env also didn't work. It's possible to to set the variable, although it threw warning:
warning: include location "/usr/local/include" is unsafe for cross-compilation [-Wpoison-system-directories]
and it does not compiles, probably it misses a few variables to export.
TL;DR Go with Fish-bax, at least it works :)

AST of a project by Clang

I use the Clang python binding to extract the AST of c/c++ files. It works perfectly for a simple program I wrote. The problem is when I want to employ it for a big project like openssl. I can run clang for any single file of the project, but clang seems to miss some headers of the project, and just gives me the AST of a few functions of the file, not all of the functions. I set the include folder by -I, but still getting part of the functions.
This is my code:
import clang.cindex as cl
cl.Config.set_library_path(clang_lib_dir)
index = cl.Index.create()
lib = 'Path to include folder'
args = ['-I{}'.format(lib)]
translation_unit = index.parse(source_file, args=args)
my_get_info(translation_unit.cursor)
I receive too many header files not found errors.
UPDATE
I used Make to compile openssl by clang? I can pass -emit-ast option to clang to dump the ast of each file, but I cannot read it now by the clang python binding.
Any clues how I can save the the serialized representation of the translation units so that I will be able to read it by index.read()?
Thank you!
You would "simply" need to provide the right args. But be aware of two possible issues.
Different files may require different arguments for parsing. The easiest solution is to obtain compilation database and then extract compile commands from it. If you go this way be aware that you would need to filter out the arguments a bit and remove things like -c FooBar.cpp (potentially some others), otherwise you may get something like ASTReadError.
Another issue is that the include paths (-I ...) may be relative to the source directory. I.e., if a file main.cpp compiled from a directory /opt/project/ with -I include/path argument, then before calling index.parse(source_file, args=args) you need to step in (chdir) into the /opt/project, and when you are done you will probably need to go back to the original working directory. So the code may look like this (pseudocode):
cwd = getcwd()
chdir('/opt/project')
translation_unit = index.parse(source_file, args=args)
chdir(cwd)
I hope it helps.

How can a parser and a lexer work together if they're in separate packages?

This question concerns Antlr, the parser/lexer generator (Which is pretty awesome IMO). Specifically, the version in question is Antlr4. Currently I'm playing around trying to create a parser/lexer combo in separate files, which worked well at first.
However, when I tried to modularize the different components, for organization's sake, I discovered an issue. The two tools I'm using to modularize, package declarations in headers and setting the parser's token vocab, work perfectly separately, but I cannot seem to get them to play nice together.
I've put together a very short example that illustrates my issue.
First, I've defined my lexer:
lexer grammar UsefulLexer;
#header{
package org.useful.lexer;
}
USEFUL_TOKEN:'I\'m useful, I promise!';
Second I've defined my parser.
parser grammar UsefulParser;
#header{
package org.useful.parser;
}
options{
tokenVocab=UsefulLexer;
}
usefulRule:USEFUL_TOKEN*;
But when I build, I get the useful error:
cannot find tokens file /Users/me/Desktop/Workspace/Project_Name/src-gen/org/useful/parser/UsefulLexer.tokens
All the rules together work perfectly together in a combined grammar, or even separately, provided they are in the same package. However, for how I'm using Antlr, with multiple parsers sharing the same lexer, having all the components in the same package defeats the purpose of using packages in the first place.
I've consulted the docs, especially the section on grammar structure, and I can't find an official source for how to fix this. I've also tried the obvious solution, changing tokenVocab=UsefulLexer to tokenVocab=org.useful.lexer.UsefulLexer, but that doesn't even parse. (Which I find somewhat ironic.)
What is the syntax I am missing? Or is this just something that there isn't syntax for?
Have to build both the lexer and parser. Here is a simple test rig builder:
#echo off
rem Execute the Antlr compiler/generator tool
rem put grammar files in "D:/DevFiles/Java/src/test/parser"
SETLOCAL
set files=../UsefulLexer.g4 ../UsefulParser.g4
set CLASSPATH=D:/DevFiles/Java/lib/antlr-4.5-complete.jar
set tool=org.antlr.v4.Tool
set cmd="C:/Program Files/Java/jre7/bin/java.exe"
set opts=-visitor
cd /d D:/DevFiles/Java/src/test/parser/gen
%cmd% %tool% %opts% %files%
ENDLOCAL
pause
rem timeout 5
To solve this, I had to modify my ANTLR build command for both the lexer and the parser, adding the -lib & -package options. Once I pointed -lib at the package of my lexer in my parser buildscript, and moved my package declarations to the build commands in both, it was smooth sailing.
Hope this helps someone else!

Path definition in makefile

I have a doubt about indicating a path in makefile and I'd like to have a clarification.
Suppose my structure is made this way:
/home/machinename/softwarefolder/mainfolder
--------------------------------------------> /subfolder1
--------------------------------------------> /subfolder2
This means that both subfolder1 and subfolder2 are at the same nesting level in /mainfolder.
Now I'm compiling something inside subfolder 2 (this means that I cd to that folder) that uses a configure file with a macro pointing to a path that, in my case, it's in subfolder1.
This configure file used by the program in subfolder2 to compile is generated automatically by the program itself after running ./configure
The automatically generated configure file has the macro defined this way
MACRO = ../subfolder1
Do the two dots (..) indicate, as in the cd command, "go back one step" (and, therefor, the configure file is pointing to the right folder)?
If the answer to the first question is "no", then why substituting the aforementioned macro with
MACRO = /home/machinename/softwarefolder/mainfolder/subfolder1
generates a "missing separator" error in compile-time?
Sorry for the probably trivial question and thanks for the help!
Make doesn't interpret the content of variables in any way, for the most part. The question of how the .. will be interpreted depends entirely on where the variable is used. If it's used in a place where a path like ../subfolder1 makes sense, then that's how it will be interpreted. If not, not.
Since you don't show how $(MACRO) is used, we can't help. But in general the answer to your question is "yes, it means go up to the parent directory".
As for your second question, there is no way I can envision that changing just that one line will result in a "missing separator" error. Maybe your editor "helpfully" made other changes to the file such as removing TABs and substituting spaces, or adding TABs? TAB characters are special in makefiles.
If you want help with the second question you must provide (a) the exact error you received (cut and paste is best), and (b) the exact text of the rule in the makefile at the line number specified in the error message.

In rails.vim why do I get "E345 can't find file in path" errors?

I've been learning Ruby/Rails with vim. Tim Pope's rails.vim seems like a really good tool to traverse files with, but I keep getting these pesky "E345 can't find file in path" errors. I'm not vim expert yet, so the solution isn't obvious. Additionally, I've tried this and it doesn't apply to my problem.
As an example of the problem. I have a method format_name defined in app/helpers/application_helper.rb and it is used in app/helpers/messages_helper.rb. Within the latter file I put my cursor over the usage of format_name and then hit gf and I get that error. Similar disfunction with commands like ]f and [f
However, it works sometimes. I was able to gf from user to the app/models/user.rb
Ideas?
I think that is a limitation of rails.vim. It does not support “finding” bare methods. Supporting something like that would require one of the following:
an exhaustive search of all the source files for each “find” request
(which could be expensive with large projects),
“dumb” indexing of method names
(e.g. Exuberant Ctags and gControl-]; see :help g_CTRL-]), or
smart enough parsing of the code to make a good guess where the method might be defined
(which is hard to do properly).
If you know where the method is, you can extend many of the navigation commands with a method name:
:Rhelper application#format_name
But, you do not have to type all of that in. Assuming the cursor is on format_name you can probably just type:RhTabspaceappTab#Control-R Control-W (see :help c_CTRL-R_CTRL-W).

Resources