1

So this is a little bit messy, however I have a single .cpp file that I want to be used in two different ways; as a c class called by a java class using JNI, and as a c program standalone. The reason for this is because this code moves around between machines and sometimes I want to just run and compile the c++ code directly as opposed to running java and having java run it. (The c++ code has a main method that is only ever ran in the standalone version).

So anyways I have the file (test.cpp) and the java source code that goes with it (test.java) in /home/user/dev/javajni/. However, I also want to be able to compile it as a standalone in /home/user/dev/standalone/. In the standalone directory I have a make file that only compiles the c program.

Anyways, when I make a hardlink to the file in javajni inside the standalone directory the makefile doesn't see it, or refuses to see the hardlink.

make: *** No rule to make target `test.cpp', needed by `test'.  Stop.

And while in the standalone directory I use:

ln /home/user/dev/javajni/test.cpp test.cpp

But when I copy the entire file over it works fine.

What's the big deal? Isn't the original file in the original location technically just a hardlink to the inode as well? I just want to be able to alter the file in one location without having to copy and paste it back and forth.

If at all useful this is what my makefile looks like:

EX=test

all: $(EX)

.cpp.o:
    g++ -c -O3 -Wall $<

clean:
    rm -f $(EX) *.o *.a


test:test.cpp;           g++ -Wall -o $@ $^

(Fyi I did change the name of the file and the directories in this post for simplification)

danglingPointer
  • 882
  • 8
  • 32
  • Does `cat test.cpp` work in the `standalone` folder? – Elliott Frisch Oct 12 '16 at 22:27
  • Check the timestamp on `/home/user/dev/javajni/test.cpp`, and check your system clock, and see if something looks strange to you. Remember, if you create the hard link, and the `.o` file is newer, it won't get recompiled. – Sam Varshavchik Oct 12 '16 at 22:27
  • Thanks for the quick reply guys. Elliott: some weird behavior, at first it told me that the file was not found. However something I did change that and now cat does output the file's contents in the `standalone` folder via the hardlink. I did change on line in the file in the `javajni` location, so perhaps that was it? In any case the make program still doesn't see it. Sam: Since this is a single .cpp made into an executable there is no `.o` file, right? Or am I missing some basic information on how compiling works? – danglingPointer Oct 12 '16 at 22:50
  • Is there a requierement for the hard link ? Why not use a soft one ? – Chnossos Oct 13 '16 at 10:43
  • Softlink didn't work either. – danglingPointer Oct 14 '16 at 06:13

0 Answers0