LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Missing separator on patchinc to C code (https://www.linuxquestions.org/questions/linux-software-2/missing-separator-on-patchinc-to-c-code-4175454630/)

chiendarret 03-19-2013 01:41 AM

Missing separator on patchinc to C code
 
Hello:
This question is addressed to specialists in C/C++ programming.

On patching a plugin to a computational C code everything runs plainly unless lapack libraries and C++ libraries are linked, as required for a special feature of the plugin. I tried linking along many routes, including full paths, as with:

LIBS="-L/usr/lib/x86_64-linux-gnu/ -lgfortran -L/usr/lib/lapack/ -llapack -L/lib/x86_64-linux-gnu/ -lm -L/usr/lib/ -lblas -L/lib/x86_64-linux-gnu/ -lpthread -L/usr/lib/gcc/x86_64-linux-gnu/4.6/ -lstdc++"

With the line "LIBS= " left blank, patching occurs. With lapack, and dependencies, and c++ libs defined, as above, the error is:


...........................
...........................
Hunk #4 succeeded at 403 with fuzz 3 (offset 51 lines).

Hunk #5 succeeded at 429 (offset 53 lines).

-- Executing post script

plumed.inc:39: *** missing separator. Stop.


- DONE!

xxxxxxxxxxxxxxxxxx
Up to "Hunk #5", it is normal output, and hunking is complete. The "missing separator" error comes out whichever is done, except leaving the line "LIBS=" blank.

My question is whether the information given is sufficient to understand whether a correction is needed to the patch code. In the area where "plumed.inc" is mentioned, it reads:

{
echo -n "PLUMED_OBJECTS="
for file in $plumedir/common_files/*.c
do f=${file##*/}
echo " \\"
echo -n " \$(DSTDIR)/${f%.c}.o"
done
echo
if [ "$RECON_LIBS" != "" ] ; then
for file in $plumedir/recon_src/*.cpp
do f=${file##*/}
echo " \\"
echo -n " \$(DSTDIR)/${f%.cpp}.o"
done
echo " "
echo "RECON_FLAGS=\$(COPTD)RECONMETAD"
else
echo " "
echo "RECON_FLAGS="
fi
echo "RECON_LIBS="$RECON_LIBS
} > $WHERE_LINKS/plumed.inc

cd $myarch ; ln -s $WHERE_LINKS/plumed.inc .; make depends ; cd ../
}


To me ":39" is particularly confusing. If it refers to line number, then it is not pointing to the area where "plumed.in" is first mentioned. Rather, much earlier.

thanks indeed

chiendarret

johnsfine 03-19-2013 06:32 PM

It looks like you have more need of help from someone knowing bash programming, not someone knowing C/C++ programming.

Quote:

Originally Posted by chiendarret (Post 4914275)
To me ":39" is particularly confusing. If it refers to line number, then it is not pointing to the area where "plumed.in" is first mentioned.

The 39 is a line number. But it is a line number inside the file plumed.inc, not a line number in the script that creates and uses plumed.inc

The code you quoted creates plumed.inc

Some other code, that I don't think you showed uses plumed.inc. But I don't know how plumed.inc is used nor what exactly prints the error message about line 39 of plumed.inc

I expect that after the whole action fails, the file plumed.inc ought to still exist. If you look at the portion around line 39, you ought to get some idea what is wrong with it, which then could be back tracked to what is wrong with the bash code that created it.

chiendarret 03-20-2013 12:06 PM

missing separator
 
hello:
You are right (believe me, after posting I also realized that :39 refers to plumed.inc but badly failed to find the file; a simple "locate' was now enough). That plumed.inc is formed, on patching, into /maindir/src and reads:
(line 39 is the mere "/" after line "$(DSTDIR)/testderivatives.o")

PLUMED_OBJECTS= \
$(DSTDIR)/biasexchange.o \
$(DSTDIR)/dafed.o \
$(DSTDIR)/hills.o \
$(DSTDIR)/metadyn.o \
$(DSTDIR)/ptmetad.o \
$(DSTDIR)/read_restraint.o \
$(DSTDIR)/restraint_adf.o \
$(DSTDIR)/restraint_alfabeta.o \
$(DSTDIR)/restraint_alpharmsd.o \
$(DSTDIR)/restraint_angle.o \
$(DSTDIR)/restraint_antibetarmsd.o \
$(DSTDIR)/restraint.o \
$(DSTDIR)/restraint_cmap.o \
$(DSTDIR)/restraint_coord.o \
$(DSTDIR)/restraint_dihcor.o \
$(DSTDIR)/restraint_dipole.o \
$(DSTDIR)/restraint_dist.o \
$(DSTDIR)/restraint_elstpot.o \
$(DSTDIR)/restraint_energy.o \
$(DSTDIR)/restraint_func.o \
$(DSTDIR)/restraint_hbonds.o \
$(DSTDIR)/restraint_helix.o \
$(DSTDIR)/restraint_histogram.o \
$(DSTDIR)/restraint_mindist.o \
$(DSTDIR)/restraint_parabetarmsd.o \
$(DSTDIR)/restraint_pca.o \
$(DSTDIR)/restraint_poly.o \
$(DSTDIR)/restraint_position.o \
$(DSTDIR)/restraint_puckering.o \
$(DSTDIR)/restraint_rdf.o \
$(DSTDIR)/restraint_rgyr.o \
$(DSTDIR)/restraint_spath.o \
$(DSTDIR)/restraint_sprint.o \
$(DSTDIR)/restraint_torsion.o \
$(DSTDIR)/restraint_waterbridge.o \
$(DSTDIR)/restraint_zpath.o \
$(DSTDIR)/testderivatives.o
\
$(DSTDIR)/recon_basins.o \
$(DSTDIR)/recon_cbind.o \
$(DSTDIR)/recon_metad.o \
$(DSTDIR)/recon_ppca.o \
$(DSTDIR)/recon_testderivatives.o \
$(DSTDIR)/recon_utils.o
RECON_FLAGS=$(COPTD)RECONMETAD
RECON_LIBS=-L/usr/lib/x86_64-linux-gnu/ -lgfortran -L/usr/lib/lapack/ -llapack -L/lib/x86_64-linux-gnu/ -lm -L/usr/lib/ -lblas -L/lib/x86_64-linux-gnu/ -lpthread -L/usr/lib/gcc/x86_64-linux-gnu/4.6/ -lstdc++

In contrast, when the line RECON_LIBS= is left blank, patching occurs, "make depends" does its job, and "make" compiles the patched main code. In this case, the last portion of /src/plumed.inc reads:

$(DSTDIR)/restraint_torsion.o \
$(DSTDIR)/restraint_waterbridge.o \
$(DSTDIR)/restraint_zpath.o \
$(DSTDIR)/testderivatives.o

RECON_FLAGS=
RECON_LIBS=

What is wrong about line 39? Or what else?

At any event, thanks a lot for your kind advice.

chiendarret

chiendarret 03-20-2013 12:12 PM

missing separator
 
Must add, if relevant, that, as opened with emacs, the whole block after line 39 "/" is left displaced by 8 characters from the preceding block of PLUMED_OBJECTS.

chiendarret

chiendarret 03-20-2013 12:27 PM

Perhaps I should also add that when patching with line "RECON_LIBS=" left blank, the patching command triggers a large number of dependencies, the same that are later seen on command "make depends".

When the libraries are linked, patching ends at "missing separator", no depencies are made and "make depends' does not work.

chiendarret

johnsfine 03-20-2013 12:47 PM

I am most definitely NOT a skilled bash programmer. So you still might need help from such a programmer.

But it seems obvious where the extra newline is getting injected into the constructed file. I marked in red the command that I think should not be there.

Code:

{
    echo -n "PLUMED_OBJECTS="
    for file in $plumedir/common_files/*.c
      do f=${file##*/}
      echo "    \\"
      echo -n "    \$(DSTDIR)/${f%.c}.o"
    done
    echo
    if [ "$RECON_LIBS" != "" ] ; then
      for file in $plumedir/recon_src/*.cpp
        do f=${file##*/}
        echo "  \\"
        echo -n " \$(DSTDIR)/${f%.cpp}.o"
      done
      echo " "
      echo "RECON_FLAGS=\$(COPTD)RECONMETAD"
    else
      echo " "
      echo "RECON_FLAGS="
    fi
    echo "RECON_LIBS="$RECON_LIBS
  } > $WHERE_LINKS/plumed.inc

  cd $myarch ; ln -s $WHERE_LINKS/plumed.inc .; make depends ; cd ../
}

Quote:

Originally Posted by chiendarret (Post 4915323)
(line 39 is the mere "/" after line "$(DSTDIR)/testderivatives.o")
...
What is wrong about line 39? Or what else?

What is wrong is that the \ alone on line 39 was supposed to be at the end of line 38.

I don't know what harm is done by having a \ alone on line 39. Most likely no harm. But not having a \ on the end of line 38 totally messes up the parsing of the file, so the next thing that gets read (line 39) will be misunderstood.

chiendarret 03-21-2013 03:18 AM

That clarifies the issue. Thanks indeed.
However, how to get "\" at the end of line 38? Generation of plumed.inc is from the patching script, a portion of which (dealing with plumed.inc) I posted initially. Below the full patching script, which is simply run with

./patchingscript.sh -patch

It would be great if you suggest a correction.
chiendarret

#!/bin/bash
# PATCH SCRIPT FOR NAMD 2.7
#

# USER DEFINED ARCHITECTURE:
myarch="Linux-x86_64-g++"

# this script needs to be launched from the root directory of the host code
destination="$PWD"

# definitions specific to this code
CODE="namd2.9"
LINKED_FILES="$plumedir/common_files/*.h $plumedir/common_files/*.c"
RECON_LINKS="$plumedir/recon_src/*.cpp $plumedir/recon_src/*.h"
WHERE_LINKS="./src/"
# Leave this line here blank for normal patching of plumed
RECON_LIBS=
# CVS version only : for reconnaissance metadynamics enter here information on the
# locations of the lapack and lstdc++ libraries.
RECON_LIBS="/usr/lib/lapack/liblapack.so.3gf.0 /usr/lib/x86_64-linux-gnu/libstdc++.so.6"

# this changes the names from .c to .C
PLUMED_RENAME_RULE=plumed_rename_rule
function plumed_rename_rule (){
case "$1" in
(*.c) echo "${1%.c}.C" ;;
(*) echo "$1" ;;
esac
}

# this changes the names from .cpp to .C
RECON_RENAME_RULE=recon_rename_rule
function recon_rename_rule (){
case "$1" in
(*.cpp) echo "${1%.cpp}.C" ;;
(*) echo "$1" ;;
esac
}

function to_do_before_patch () {
echo > /dev/null
}

function to_do_after_patch () {
{
echo -n "PLUMED_OBJECTS="
for file in $plumedir/common_files/*.c
do f=${file##*/}
echo " \\"
echo -n " \$(DSTDIR)/${f%.c}.o"
done
echo
if [ "$RECON_LIBS" != "" ] ; then
for file in $plumedir/recon_src/*.cpp
do f=${file##*/}
echo " \\"
echo -n " \$(DSTDIR)/${f%.cpp}.o"
done
echo " "
echo "RECON_FLAGS=\$(COPTD)RECONMETAD"
else
echo " "
echo "RECON_FLAGS="
fi
echo "RECON_LIBS="$RECON_LIBS
} > $WHERE_LINKS/plumed.inc

cd $myarch ; ln -s $WHERE_LINKS/plumed.inc .; make depends ; cd ../
}

function to_do_before_revert () {
rm $myarch/plumed.inc; rm $WHERE_LINKS/plumed.inc
}

function to_do_after_revert () {
cd $myarch ; make depends ; cd ../
}

#########

NAME="$0"
source $plumedir/patches/patch_tool.sh

johnsfine 03-21-2013 08:19 AM

Quote:

Originally Posted by chiendarret (Post 4915777)
However, how to get "\" at the end of line 38?

I thought I had explained that.

There is an echo command in the script which I think should be removed. I identified that in red in my previous post. (I hope your browser is showing you colors).

That echo command is responsible for the line break between lines 38 and 39 of plumed.inc. If you remove that echo command, then those two lines of plumed.inc will be merged together (which I think is what you need).

Quote:

It would be great if you suggest a correction.
Remove line 52 of the full script you quoted, that is the echo right before:
if [ "$RECON_LIBS" != "" ] ; then

chiendarret 03-21-2013 09:54 AM

Hello:
I corrected plumed.inc according to your suggestion: moved "\" from line 39 to the end of line 38 and no blank line with the following. "make depends" issued the dependencies and "make" compiled the main program.
Still to check if everything is in order (which will also depends on the link to the libraries) but the main program executables were generated. I'll check in a few days, now busy.

thanks a lot
chiendarret

chiendarret 03-21-2013 10:01 AM

SOLVED missing-separator
 
I did not notice your suggestion

Remove line 52 of the full script you quoted, that is the echo right before:
if [ "$RECON_LIBS" != "" ] ; then

or I preceded your suggestion, when I adjusted plumed.inc and posted.

I'll check the executable as soon as I am finished with a new affair. At any event, I'll implement your suggestion. Thanks
chiendarret


All times are GMT -5. The time now is 04:13 AM.