PDA

View Full Version : Generated absolute path via for in doesn't exist



awsdert
02-04-2019, 12:38 PM
This is seriously confusing me, this:


PRJ_DIR=$(pwd)/
SRC_DIR=${PRJ_DIR}
OUT_DIR="${ALL}/lu"
OBJ_DIR=${PRJ_DIR}objs
chkdir "${OBJ_DIR}"
OBJ_DIR="${OBJ_DIR}/${O_DIR}"
...
echo Compiling Lu Objects
chkdir "${OBJ_DIR}"
chknam(){
n=$(basename $1)
compile_obj "${OBJ_DIR}/$n.o" $1 true
}
for i in "${SRC_DIR}"*.c
do
chknam "$i"
done
unset chknam

Resulted in this:


sh build.sh (in directory: /media/zxuiji/ZXUIJI_1TB/github/lu/lu)
CPATH=/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src
LPATH=/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5
Compiling Lu Objects
gcc -Wall -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/gcc/LuScript.c.o" -c "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/LuScript.c"
gcc: error: "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/LuScript.c": No such file or directory
gcc: fatal error: no input files
compilation terminated.
...

awsdert
02-06-2019, 04:07 AM
Found the problem, apparently gcc & other compilers must be run with root permissions ( ͠ ͟ʖ ͡)

Edit: Nope, only works when I type directly, this is sooo WTF!?
Here's a root permission terminal output trying both


root@zxuiji-mint:/media/zxuiji/ZXUIJI_1TB/github/lu/lu# clang lu.c
In file included from lu.c:1:
./lu.h:34:10: fatal error: 'lua.h' file not found
#include <lua.h>
^~~~~~~
1 error generated.
root@zxuiji-mint:/media/zxuiji/ZXUIJI_1TB/github/lu/lu# sh build.sh
CPATH=/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src
LPATH=/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5
Compiling Lu Objects from /media/zxuiji/ZXUIJI_1TB/github/lu/lu
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/LuScript.c".o" -c "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/LuScript.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/github/lu/lu/LuScript.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lu.c".o" -c "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/lu.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/github/lu/lu/lu.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/luat.c".o" -c "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/luat.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/github/lu/lu/luat.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/ludir.c".o" -c "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/ludir.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/github/lu/lu/ludir.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lufile.c".o" -c "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/lufile.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/github/lu/lu/lufile.c"'
clang: error: no input files
Compiling Lua Objects from /media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lapi.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lapi.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lapi.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lauxlib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lauxlib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lauxlib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lbaselib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lbaselib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lbaselib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lbitlib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lbitlib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lbitlib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lcode.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lcode.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lcode.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lcorolib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lcorolib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lcorolib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lctype.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lctype.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lctype.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/ldblib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ldblib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ldblib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/ldebug.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ldebug.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ldebug.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/ldo.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ldo.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ldo.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/ldump.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ldump.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ldump.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lfunc.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lfunc.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lfunc.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lgc.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lgc.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lgc.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/linit.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/linit.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/linit.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/liolib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/liolib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/liolib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/llex.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/llex.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/llex.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lmathlib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lmathlib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lmathlib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lmem.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lmem.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lmem.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/loadlib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/loadlib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/loadlib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lobject.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lobject.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lobject.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lopcodes.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lopcodes.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lopcodes.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/loslib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/loslib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/loslib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lparser.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lparser.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lparser.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lstate.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lstate.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lstate.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lstring.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lstring.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lstring.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lstrlib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lstrlib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lstrlib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/ltable.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ltable.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ltable.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/ltablib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ltablib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ltablib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/ltm.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ltm.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/ltm.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lua.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lua.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lua.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/luac.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/luac.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/luac.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lundump.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lundump.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lundump.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lutf8lib.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lutf8lib.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lutf8lib.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lvm.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lvm.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lvm.c"'
clang: error: no input files
sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/lua/lzio.c".o" -c "/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lzio.c"
clang: error: no such file or directory: '"/media/zxuiji/ZXUIJI_1TB/common/lua-5.3.5/src/lzio.c"'
clang: error: no input files
Compiling Lu Executable
clang: error: no input files
root@zxuiji-mint:/media/zxuiji/ZXUIJI_1TB/github/lu/lu#

Salem
02-06-2019, 04:21 AM
> sudo clang -Wall -Wextra -Werror -o "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/objs/clang/LuScript.c".o" -c "/media/zxuiji/ZXUIJI_1TB/github/lu/lu/LuScript.c"
Well there's certainly no reason for running the compiler as root, unless you have basically no permissions to write to directories.

A problem might be your mis-matched quotes on the .o file

awsdert
02-06-2019, 04:31 AM
Okay tried modifying my build script to put the full command in a string and it finally found the file, makes me think the shell puts it in a fake environment when executing via a variable's contents, here's the snippet I'm using after modified the script several times and reaching this point:


compile_c() {
local c="${CC} ${CFLAGS}"
echo "$1 from $3"
chkdir "$2"
for i in "$3/"*.c
do
n="$(basename \"$i\")"
o="$2/$n.o"
if chknam "$n" "$o" "$i"; then
echo $c -o "$o" -c "$i"
$c -o "$o" -c "$i"
fi
done
}

compile_c "Compiling Lu Objects" "${OBJ_DIR}" "${SRC_DIR}"
compile_c "Compiling Lua Objects" "${OBJ_LUA_DIR}" "${SRC_LUA_DIR}"