I am facing a problem in correctly compiling CUDA code containing dynamic parallelism.
The problem is that compilation and linking show no error, but the generated file is invalid executable.
Configuration:
Tesla K40, Ubuntu 14.04 LTS, CUDA 7.5
Compilation Command:
nvcc -o cdp -rdc=true -dc -dlink -arch=sm_35 cdp.cu -lcudadevrt
Code:
#include <iostream>
#include <cuda_runtime.h>
using namespace std;
__global__ void kernel_find(int* data, int count, int value, int* index)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if(idx<count)
{
bool exists = (data[idx] == value);
if(exists)
atomicMin(index, idx);
}
}
__host__ __device__ int find_device(int* data, int count, int value)
{
int* idx = new int;
(*idx) = count;
dim3 block(8);
dim3 grid((count + block.x - 1)/block.x);
kernel_find<<<grid, block>>>(data, count, value, idx);
cudaDeviceSynchronize();
int retval = *idx;
delete idx;
return retval;
}
__global__ void kernel_find_bulk(int* data, int count, const int* toFind, int* foundIndices, int toFindCount)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if(idx<toFindCount)
{
int val = toFind[idx];
int foundIndex = find_device(data, count, val);
foundIndices[idx] = foundIndex;
}
}
int main()
{
const int count = 100, toFindCount = 10;
int *data, *toFind, *foundIndices;
cudaMallocManaged(&data, count * sizeof(int));
cudaMallocManaged(&toFind, toFindCount * sizeof(int));
cudaMallocManaged(&foundIndices, toFindCount * sizeof(int));
for(int i=0; i<count; i++)
{
data[i] = rand() % 30;
}
for(int i=0; i<toFindCount; i++)
{
toFind[i] = i;
}
dim3 block(8);
dim3 grid((toFindCount + block.x - 1)/block.x);
kernel_find_bulk<<<grid, block>>>(data, count, toFind, foundIndices, toFindCount);
cudaDeviceSynchronize();
for(int i=0; i<toFindCount; i++)
{
if(foundIndices[i] < count)
{
cout<<toFind[i]<<" found at index "<<foundIndices[i]<<endl;
}
else
{
cout<<toFind[i]<<" not found"<<endl;
}
}
return 0;
}
If I try to run the executable, I get Permission denied error. If permissions are changed forcefully using chmod, the error changes to cannot execute binary file: Exec format error.
I can't figure out the solution, as CUDA dynamic parallelism samples are running fine and CUDA programs without Dynamic Parallelism are also working fine. Any help would be appreciated.
Output of file command:
cdp: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not
stripped
Output of objdump -f command:
cdp: file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x0000000000000000
If you run your compile command with the --dryrun option:
$ nvcc --dryrun -o cdp -rdc=true -dc -dlink -arch=sm_35 cdp.cu -lcudadevrt
#$ _SPACE_=
#$ _CUDART_=cudart
#$ _HERE_=/opt/cuda-7.5/bin
#$ _THERE_=/opt/cuda-7.5/bin
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_SIZE_=64
#$ TOP=/opt/cuda-7.5/bin/..
#$ NVVMIR_LIBRARY_DIR=/opt/cuda-7.5/bin/../nvvm/libdevice
#$ LD_LIBRARY_PATH=/opt/cuda-7.5/bin/../lib:/opt/cuda-7.5/lib64
#$ PATH=/opt/cuda-7.5/bin/../open64/bin:/opt/cuda-7.5/bin/../nvvm/bin:/opt/cuda-7.5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/cuda-7.5/bin
#$ INCLUDES="-I/opt/cuda-7.5/bin/..//include"
#$ LIBRARIES= "-L/opt/cuda-7.5/bin/..//lib64/stubs" "-L/opt/cuda-7.5/bin/..//lib64"
#$ CUDAFE_FLAGS=
#$ PTXAS_FLAGS=
#$ gcc -D__CUDA_ARCH__=350 -E -x c++ -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__ -D__NVCC__ -D__CUDACC_RDC__ "-I/opt/cuda-7.5/bin/..//include" -D"__CUDACC_VER__=70517" -D"__CUDACC_VER_BUILD__=17" -D"__CUDACC_VER_MINOR__=5" -D"__CUDACC_VER_MAJOR__=7" -include "cuda_runtime.h" -m64 "cdp.cu" > "/tmp/tmpxft_000022ba_00000000-7_cdp.cpp1.ii"
#$ cudafe --allow_managed --m64 --gnu_version=40603 -tused --no_remove_unneeded_entities --device-c --gen_c_file_name "/tmp/tmpxft_000022ba_00000000-4_cdp.cudafe1.c" --stub_file_name "/tmp/tmpxft_000022ba_00000000-4_cdp.cudafe1.stub.c" --gen_device_file_name "/tmp/tmpxft_000022ba_00000000-4_cdp.cudafe1.gpu" --nv_arch "compute_35" --gen_module_id_file --module_id_file_name "/tmp/tmpxft_000022ba_00000000-3_cdp.module_id" --include_file_name "tmpxft_000022ba_00000000-2_cdp.fatbin.c" "/tmp/tmpxft_000022ba_00000000-7_cdp.cpp1.ii"
#$ gcc -D__CUDA_ARCH__=350 -E -x c -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__ -D__NVCC__ -D__CUDACC_RDC__ -D__CUDANVVM__ -D__CUDA_PREC_DIV -D__CUDA_PREC_SQRT "-I/opt/cuda-7.5/bin/..//include" -m64 "/tmp/tmpxft_000022ba_00000000-4_cdp.cudafe1.gpu" > "/tmp/tmpxft_000022ba_00000000-8_cdp.cpp2.i"
#$ cudafe -w --allow_managed --m64 --gnu_version=40603 --c --device-c --gen_c_file_name "/tmp/tmpxft_000022ba_00000000-9_cdp.cudafe2.c" --stub_file_name "/tmp/tmpxft_000022ba_00000000-9_cdp.cudafe2.stub.c" --gen_device_file_name "/tmp/tmpxft_000022ba_00000000-9_cdp.cudafe2.gpu" --nv_arch "compute_35" --module_id_file_name "/tmp/tmpxft_000022ba_00000000-3_cdp.module_id" --include_file_name "tmpxft_000022ba_00000000-2_cdp.fatbin.c" "/tmp/tmpxft_000022ba_00000000-8_cdp.cpp2.i"
#$ gcc -D__CUDA_ARCH__=350 -E -x c -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDABE__ -D__CUDANVVM__ -D__CUDA_PREC_DIV -D__CUDA_PREC_SQRT "-I/opt/cuda-7.5/bin/..//include" -m64 "/tmp/tmpxft_000022ba_00000000-9_cdp.cudafe2.gpu" > "/tmp/tmpxft_000022ba_00000000-10_cdp.cpp3.i"
#$ filehash -s "--compile-only " "/tmp/tmpxft_000022ba_00000000-10_cdp.cpp3.i" > "/tmp/tmpxft_000022ba_00000000-11_cdp.hash"
#$ gcc -E -x c++ -D__CUDACC__ -D__NVCC__ -D__CUDACC_RDC__ "-I/opt/cuda-7.5/bin/..//include" -D"__CUDACC_VER__=70517" -D"__CUDACC_VER_BUILD__=17" -D"__CUDACC_VER_MINOR__=5" -D"__CUDACC_VER_MAJOR__=7" -include "cuda_runtime.h" -m64 "cdp.cu" > "/tmp/tmpxft_000022ba_00000000-5_cdp.cpp4.ii"
#$ cudafe++ --allow_managed --m64 --gnu_version=40603 --parse_templates --device-c --gen_c_file_name "/tmp/tmpxft_000022ba_00000000-4_cdp.cudafe1.cpp" --stub_file_name "tmpxft_000022ba_00000000-4_cdp.cudafe1.stub.c" --module_id_file_name "/tmp/tmpxft_000022ba_00000000-3_cdp.module_id" "/tmp/tmpxft_000022ba_00000000-5_cdp.cpp4.ii"
#$ cicc -arch compute_35 -m64 -ftz=0 -prec_div=1 -prec_sqrt=1 -fmad=1 -nvvmir-library "/opt/cuda-7.5/bin/../nvvm/libdevice/libdevice.compute_35.10.bc" --device-c --orig_src_file_name "cdp.cu" "/tmp/tmpxft_000022ba_00000000-10_cdp.cpp3.i" -o "/tmp/tmpxft_000022ba_00000000-6_cdp.ptx"
#$ ptxas -arch=sm_35 -m64 --compile-only "/tmp/tmpxft_000022ba_00000000-6_cdp.ptx" -o "/tmp/tmpxft_000022ba_00000000-13_cdp.sm_35.cubin"
#$ fatbinary --create="/tmp/tmpxft_000022ba_00000000-2_cdp.fatbin" -64 --key="xxxxxxxxxx" --cmdline="--compile-only " "--image=profile=sm_35,file=/tmp/tmpxft_000022ba_00000000-13_cdp.sm_35.cubin" "--image=profile=compute_35,file=/tmp/tmpxft_000022ba_00000000-6_cdp.ptx" --embedded-fatbin="/tmp/tmpxft_000022ba_00000000-2_cdp.fatbin.c" --cuda --device-c
#$ rm /tmp/tmpxft_000022ba_00000000-2_cdp.fatbin
#$ gcc -D__CUDA_ARCH__=350 -E -x c++ -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDA_PREC_DIV -D__CUDA_PREC_SQRT "-I/opt/cuda-7.5/bin/..//include" -m64 "/tmp/tmpxft_000022ba_00000000-4_cdp.cudafe1.cpp" > "/tmp/tmpxft_000022ba_00000000-14_cdp.ii"
#$ gcc -c -x c++ "-I/opt/cuda-7.5/bin/..//include" -fpreprocessed -m64 -o "cdp" "/tmp/tmpxft_000022ba_00000000-14_cdp.ii"
it becomes obvious that this has only emitted a host object file with an embedded cubin payload. There is no host code compilation or linking to an executable, which is confirmed by the output of objdump posted in an edit to your question.
The complicating factor here is that you must perform device independent compilation to use dynamic parallelism and then link the device code, but you only have a single source file, so the conventional build approach (device compile, device link, host compile) would fail with duplicate symbols.
The solution seems to be this:
$ nvcc --dryrun -o cdp -rdc=true -arch=sm_35 cdp.cu
#$ _SPACE_=
#$ _CUDART_=cudart
#$ _HERE_=/opt/cuda-7.5/bin
#$ _THERE_=/opt/cuda-7.5/bin
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_SIZE_=64
#$ TOP=/opt/cuda-7.5/bin/..
#$ NVVMIR_LIBRARY_DIR=/opt/cuda-7.5/bin/../nvvm/libdevice
#$ LD_LIBRARY_PATH=/opt/cuda-7.5/bin/../lib:/opt/cuda-7.5/lib64
#$ PATH=/opt/cuda-7.5/bin/../open64/bin:/opt/cuda-7.5/bin/../nvvm/bin:/opt/cuda-7.5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/cuda-7.5/bin
#$ INCLUDES="-I/opt/cuda-7.5/bin/..//include"
#$ LIBRARIES= "-L/opt/cuda-7.5/bin/..//lib64/stubs" "-L/opt/cuda-7.5/bin/..//lib64"
#$ CUDAFE_FLAGS=
#$ PTXAS_FLAGS=
#$ gcc -D__CUDA_ARCH__=350 -E -x c++ -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__ -D__NVCC__ -D__CUDACC_RDC__ "-I/opt/cuda-7.5/bin/..//include" -D"__CUDACC_VER__=70517" -D"__CUDACC_VER_BUILD__=17" -D"__CUDACC_VER_MINOR__=5" -D"__CUDACC_VER_MAJOR__=7" -include "cuda_runtime.h" -m64 "cdp.cu" > "/tmp/tmpxft_00002454_00000000-9_cdp.cpp1.ii"
#$ cudafe --allow_managed --m64 --gnu_version=40603 -tused --no_remove_unneeded_entities --device-c --gen_c_file_name "/tmp/tmpxft_00002454_00000000-4_cdp.cudafe1.c" --stub_file_name "/tmp/tmpxft_00002454_00000000-4_cdp.cudafe1.stub.c" --gen_device_file_name "/tmp/tmpxft_00002454_00000000-4_cdp.cudafe1.gpu" --nv_arch "compute_35" --gen_module_id_file --module_id_file_name "/tmp/tmpxft_00002454_00000000-3_cdp.module_id" --include_file_name "tmpxft_00002454_00000000-2_cdp.fatbin.c" "/tmp/tmpxft_00002454_00000000-9_cdp.cpp1.ii"
#$ gcc -D__CUDA_ARCH__=350 -E -x c -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__ -D__NVCC__ -D__CUDACC_RDC__ -D__CUDANVVM__ -D__CUDA_PREC_DIV -D__CUDA_PREC_SQRT "-I/opt/cuda-7.5/bin/..//include" -m64 "/tmp/tmpxft_00002454_00000000-4_cdp.cudafe1.gpu" > "/tmp/tmpxft_00002454_00000000-10_cdp.cpp2.i"
#$ cudafe -w --allow_managed --m64 --gnu_version=40603 --c --device-c --gen_c_file_name "/tmp/tmpxft_00002454_00000000-11_cdp.cudafe2.c" --stub_file_name "/tmp/tmpxft_00002454_00000000-11_cdp.cudafe2.stub.c" --gen_device_file_name "/tmp/tmpxft_00002454_00000000-11_cdp.cudafe2.gpu" --nv_arch "compute_35" --module_id_file_name "/tmp/tmpxft_00002454_00000000-3_cdp.module_id" --include_file_name "tmpxft_00002454_00000000-2_cdp.fatbin.c" "/tmp/tmpxft_00002454_00000000-10_cdp.cpp2.i"
#$ gcc -D__CUDA_ARCH__=350 -E -x c -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDABE__ -D__CUDANVVM__ -D__CUDA_PREC_DIV -D__CUDA_PREC_SQRT "-I/opt/cuda-7.5/bin/..//include" -m64 "/tmp/tmpxft_00002454_00000000-11_cdp.cudafe2.gpu" > "/tmp/tmpxft_00002454_00000000-12_cdp.cpp3.i"
#$ filehash -s "--compile-only " "/tmp/tmpxft_00002454_00000000-12_cdp.cpp3.i" > "/tmp/tmpxft_00002454_00000000-13_cdp.hash"
#$ gcc -E -x c++ -D__CUDACC__ -D__NVCC__ -D__CUDACC_RDC__ "-I/opt/cuda-7.5/bin/..//include" -D"__CUDACC_VER__=70517" -D"__CUDACC_VER_BUILD__=17" -D"__CUDACC_VER_MINOR__=5" -D"__CUDACC_VER_MAJOR__=7" -include "cuda_runtime.h" -m64 "cdp.cu" > "/tmp/tmpxft_00002454_00000000-5_cdp.cpp4.ii"
#$ cudafe++ --allow_managed --m64 --gnu_version=40603 --parse_templates --device-c --gen_c_file_name "/tmp/tmpxft_00002454_00000000-4_cdp.cudafe1.cpp" --stub_file_name "tmpxft_00002454_00000000-4_cdp.cudafe1.stub.c" --module_id_file_name "/tmp/tmpxft_00002454_00000000-3_cdp.module_id" "/tmp/tmpxft_00002454_00000000-5_cdp.cpp4.ii"
#$ cicc -arch compute_35 -m64 -ftz=0 -prec_div=1 -prec_sqrt=1 -fmad=1 -nvvmir-library "/opt/cuda-7.5/bin/../nvvm/libdevice/libdevice.compute_35.10.bc" --device-c --orig_src_file_name "cdp.cu" "/tmp/tmpxft_00002454_00000000-12_cdp.cpp3.i" -o "/tmp/tmpxft_00002454_00000000-6_cdp.ptx"
#$ ptxas -arch=sm_35 -m64 --compile-only "/tmp/tmpxft_00002454_00000000-6_cdp.ptx" -o "/tmp/tmpxft_00002454_00000000-15_cdp.sm_35.cubin"
#$ fatbinary --create="/tmp/tmpxft_00002454_00000000-2_cdp.fatbin" -64 --key="xxxxxxxxxx" --cmdline="--compile-only " "--image=profile=sm_35,file=/tmp/tmpxft_00002454_00000000-15_cdp.sm_35.cubin" "--image=profile=compute_35,file=/tmp/tmpxft_00002454_00000000-6_cdp.ptx" --embedded-fatbin="/tmp/tmpxft_00002454_00000000-2_cdp.fatbin.c" --cuda --device-c
#$ rm /tmp/tmpxft_00002454_00000000-2_cdp.fatbin
#$ gcc -D__CUDA_ARCH__=350 -E -x c++ -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDA_PREC_DIV -D__CUDA_PREC_SQRT "-I/opt/cuda-7.5/bin/..//include" -m64 "/tmp/tmpxft_00002454_00000000-4_cdp.cudafe1.cpp" > "/tmp/tmpxft_00002454_00000000-16_cdp.ii"
#$ gcc -c -x c++ "-I/opt/cuda-7.5/bin/..//include" -fpreprocessed -m64 -o "/tmp/tmpxft_00002454_00000000-17_cdp.o" "/tmp/tmpxft_00002454_00000000-16_cdp.ii"
#$ nvlink --arch=sm_35 --register-link-binaries="/tmp/tmpxft_00002454_00000000-7_cdp_dlink.reg.c" -m64 "-L/opt/cuda-7.5/bin/..//lib64/stubs" "-L/opt/cuda-7.5/bin/..//lib64" -cpu-arch=X86_64 "/tmp/tmpxft_00002454_00000000-17_cdp.o" -lcudadevrt -o "/tmp/tmpxft_00002454_00000000-18_cdp_dlink.sm_35.cubin"
#$ fatbinary --create="/tmp/tmpxft_00002454_00000000-8_cdp_dlink.fatbin" -64 --key="cdp_dlink" --cmdline="--compile-only " -link "--image=profile=sm_35,file=/tmp/tmpxft_00002454_00000000-18_cdp_dlink.sm_35.cubin" --embedded-fatbin="/tmp/tmpxft_00002454_00000000-8_cdp_dlink.fatbin.c"
#$ rm /tmp/tmpxft_00002454_00000000-8_cdp_dlink.fatbin
#$ gcc -c -x c++ -DFATBINFILE="\"/tmp/tmpxft_00002454_00000000-8_cdp_dlink.fatbin.c\"" -DREGISTERLINKBINARYFILE="\"/tmp/tmpxft_00002454_00000000-7_cdp_dlink.reg.c\"" -I. "-I/opt/cuda-7.5/bin/..//include" -D"__CUDACC_VER__=70517" -D"__CUDACC_VER_BUILD__=17" -D"__CUDACC_VER_MINOR__=5" -D"__CUDACC_VER_MAJOR__=7" -m64 -o "/tmp/tmpxft_00002454_00000000-19_cdp_dlink.o" "/opt/cuda-7.5/bin/crt/link.stub"
#$ g++ -m64 -o "cdp" -Wl,--start-group "/tmp/tmpxft_00002454_00000000-19_cdp_dlink.o" "/tmp/tmpxft_00002454_00000000-17_cdp.o" "-L/opt/cuda-7.5/bin/..//lib64/stubs" "-L/opt/cuda-7.5/bin/..//lib64" -lcudadevrt -lcudart_static -lrt -lpthread -ldl -Wl,--end-group
i.e. just pass -rdc=true. It seems for the single source file case, the necessary device link stage in implicitly performed, and the result is an executable which should work:
$ nvcc -o cdp -rdc=true -arch=sm_35 cdp.cu
$ file cdp
cdp: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xdcd6119fb9e2efdf2759093e8e9b762d0a55ddfd, not stripped
Note that I haven't run this because I am doing the build on a system with a GPU without dynamic parallelism support.
Related
I have to handle very long numbers in C++. I saw online that the easiest way to do it is install the GMP library, but I have a problem.
When i execute the msys.bat file inside the compiler folder and when i execute the command ./configure --prefix=/d/Libraries_For_C_and_C++/GMP --enable-cxx it gives me an error
configure: error: could not find a working compiler, see config.log for details
I have tried to install the compiler several times but the error message is the same.
The config.log file is:
> This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake.
>
> It was created by GNU MP configure 6.1.2, which was generated by GNU
> Autoconf 2.69. Invocation command line was
>
> $ ./configure --prefix=/d/Libraries_For_C_and_C++/GMP --enable-cxx
>
> ## --------- ##
> ## Platform. ##
> ## --------- ##
>
> hostname = DESKTOP-N92E9KJ uname -m = i686 uname -r = 1.0.19(0.48/3/2)
> uname -s = MINGW32_NT-6.2 uname -v = 2016-07-13 17:45
>
> /usr/bin/uname -p = unknown /bin/uname -X = unknown
>
> /bin/arch = unknown /usr/bin/arch -k = unknown
> /usr/convex/getsysinfo = unknown /usr/bin/hostinfo = unknown
> /bin/machine = unknown /usr/bin/oslevel = unknown
> /bin/universe = unknown
>
> PATH: . PATH: /usr/local/bin PATH: /mingw/bin PATH: /bin PATH:
> /c/Program Files (x86)/Common Files/Oracle/Java/javapath PATH:
> /c/Windows/system32 PATH: /c/Windows PATH: /c/Windows/System32/Wbem
> PATH: /c/Windows/System32/WindowsPowerShell/v1.0/ PATH:
> /c/Windows/System32/OpenSSH/ PATH: /c/Program Files (x86)/NVIDIA
> Corporation/PhysX/Common PATH: /c/Users/Novati
> Giovanni/AppData/Local/Microsoft/WindowsApps PATH: .
>
>
> ## ----------- ##
> ## Core tests. ##
> ## ----------- ##
>
> configure:3055: checking build system type configure:3069: result:
> i686-pc-mingw32 configure:3089: checking host system type
> configure:3102: result: i686-pc-mingw32 configure:3139: checking for a
> BSD-compatible install configure:3207: result: /bin/install -c
> configure:3218: checking whether build environment is sane
> configure:3273: result: yes configure:3424: checking for a thread-safe
> mkdir -p configure:3463: result: /bin/mkdir -p configure:3470:
> checking for gawk configure:3486: found /bin/gawk configure:3497:
> result: gawk configure:3508: checking whether make sets $(MAKE)
> configure:3530: result: yes configure:3559: checking whether make
> supports nested variables configure:3576: result: yes configure:3705:
> checking whether to enable maintainer-specific portions of Makefiles
> configure:3714: result: no User: ABI= CC= CFLAGS=(unset)
> CPPFLAGS=(unset) MPN_PATH= GMP: abilist=32 cclist=gcc icc cc
> configure:5801: gcc 2>&1 | grep xlc >/dev/null configure:5804: $? = 1
> configure:5858: checking compiler gcc -m32 -O2 -pedantic
> -fomit-frame-pointer Test compile: configure:5872: gcc -m32 -O2 -pedantic -fomit-frame-pointer conftest.c >&5 ./configure: line 5873: gcc: command not found configure:5875: $? = 127 failed program was:
>
> int main () { return 0; } configure:6962: result: no configure:5858:
> checking compiler gcc -O2 -pedantic -fomit-frame-pointer Test
> compile: configure:5872: gcc -O2 -pedantic -fomit-frame-pointer
> conftest.c >&5 ./configure: line 5873: gcc: command not found
> configure:5875: $? = 127 failed program was:
>
> int main () { return 0; } configure:6962: result: no configure:5779:
> icc -c conftest.c >&5 ./configure: line 5780: icc: command not found
> configure:5782: $? = 127 configure:5801: icc 2>&1 | grep xlc
> >/dev/null configure:5804: $? = 1 configure:5858: checking compiler icc -no-gcc Test compile: configure:5872: icc -no-gcc conftest.c
> >&5 ./configure: line 5873: icc: command not found configure:5875: $? = 127 failed program was:
>
> int main () { return 0; } configure:6962: result: no configure:5779:
> cc -c conftest.c >&5 ./configure: line 5780: cc: command not found
> configure:5782: $? = 127 configure:5801: cc 2>&1 | grep xlc >/dev/null
> configure:5804: $? = 1 configure:5858: checking compiler cc -O Test
> compile: configure:5872: cc -O conftest.c >&5 ./configure: line
> 5873: cc: command not found configure:5875: $? = 127 failed program
> was:
>
> int main () { return 0; } configure:6962: result: no configure:7200:
> error: could not find a working compiler, see config.log for details
>
> ## ---------------- ##
> ## Cache variables. ##
> ## ---------------- ##
>
> ac_cv_build=i686-pc-mingw32 ac_cv_env_ABI_set= ac_cv_env_ABI_value=
> ac_cv_env_CCC_set= ac_cv_env_CCC_value= ac_cv_env_CC_FOR_BUILD_set=
> ac_cv_env_CC_FOR_BUILD_value= ac_cv_env_CC_set= ac_cv_env_CC_value=
> ac_cv_env_CFLAGS_set= ac_cv_env_CFLAGS_value= ac_cv_env_CPPFLAGS_set=
> ac_cv_env_CPPFLAGS_value= ac_cv_env_CPP_FOR_BUILD_set=
> ac_cv_env_CPP_FOR_BUILD_value= ac_cv_env_CPP_set= ac_cv_env_CPP_value=
> ac_cv_env_CXXCPP_set= ac_cv_env_CXXCPP_value= ac_cv_env_CXXFLAGS_set=
> ac_cv_env_CXXFLAGS_value= ac_cv_env_CXX_set= ac_cv_env_CXX_value=
> ac_cv_env_LDFLAGS_set= ac_cv_env_LDFLAGS_value= ac_cv_env_LIBS_set=
> ac_cv_env_LIBS_value= ac_cv_env_LT_SYS_LIBRARY_PATH_set=
> ac_cv_env_LT_SYS_LIBRARY_PATH_value= ac_cv_env_M4_set=
> ac_cv_env_M4_value= ac_cv_env_YACC_set= ac_cv_env_YACC_value=
> ac_cv_env_YFLAGS_set= ac_cv_env_YFLAGS_value=
> ac_cv_env_build_alias_set= ac_cv_env_build_alias_value=
> ac_cv_env_host_alias_set= ac_cv_env_host_alias_value=
> ac_cv_env_target_alias_set= ac_cv_env_target_alias_value=
> ac_cv_host=i686-pc-mingw32 ac_cv_path_install='/bin/install -c'
> ac_cv_path_mkdir=/bin/mkdir ac_cv_prog_AWK=gawk
> ac_cv_prog_make_make_set=yes am_cv_make_support_nested_variables=yes
>
> ## ----------------- ##
> ## Output variables. ##
> ## ----------------- ##
>
> ABI='' ACLOCAL='${SHELL} /d/Libraries_For_C_and_C++/gmp-6.1.2/missing
> aclocal-1.15' AMTAR='$${TAR-tar}' AM_BACKSLASH='\'
> AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' AM_DEFAULT_VERBOSITY='1'
> AM_V='$(V)' AR='' AS='' ASMFLAGS='' AUTOCONF='${SHELL}
> /d/Libraries_For_C_and_C++/gmp-6.1.2/missing autoconf'
> AUTOHEADER='${SHELL} /d/Libraries_For_C_and_C++/gmp-6.1.2/missing
> autoheader' AUTOMAKE='${SHELL}
> /d/Libraries_For_C_and_C++/gmp-6.1.2/missing automake-1.15' AWK='gawk'
> CALLING_CONVENTIONS_OBJS='x86call.lo x86check$U.lo' CC='' CCAS=''
> CC_FOR_BUILD='' CFLAGS='' CPP='' CPPFLAGS='' CPP_FOR_BUILD='' CXX=''
> CXXCPP='' CXXFLAGS='' CYGPATH_W='echo' DEFN_LONG_LONG_LIMB='' DEFS=''
> DLLTOOL='' DSYMUTIL='' DUMPBIN='' ECHO_C='' ECHO_N='-n' ECHO_T=''
> EGREP='' ENABLE_STATIC_FALSE='' ENABLE_STATIC_TRUE='' EXEEXT=''
> EXEEXT_FOR_BUILD='' FGREP='' GMP_LDFLAGS='' GMP_LIMB_BITS=''
> GMP_NAIL_BITS='0' GREP='' HAVE_CLOCK_01='' HAVE_CPUTIME_01=''
> HAVE_GETRUSAGE_01='' HAVE_GETTIMEOFDAY_01=''
> HAVE_HOST_CPU_FAMILY_power='0' HAVE_HOST_CPU_FAMILY_powerpc='0'
> HAVE_SIGACTION_01='' HAVE_SIGALTSTACK_01='' HAVE_SIGSTACK_01=''
> HAVE_STACK_T_01='' HAVE_SYS_RESOURCE_H_01='' INSTALL_DATA='${INSTALL}
> -m 644' INSTALL_PROGRAM='${INSTALL}' INSTALL_SCRIPT='${INSTALL}' INSTALL_STRIP_PROGRAM='$(install_sh) -c -s' LD='' LDFLAGS='' LEX=''
> LEXLIB='' LEX_OUTPUT_ROOT='' LIBCURSES='' LIBGMPXX_LDFLAGS=''
> LIBGMP_DLL='' LIBGMP_LDFLAGS='' LIBM='' LIBM_FOR_BUILD='' LIBOBJS=''
> LIBREADLINE='' LIBS='' LIBTOOL='' LIPO='' LN_S='' LTLIBOBJS=''
> LT_SYS_LIBRARY_PATH='' M4='' MAINT='#' MAINTAINER_MODE_FALSE=''
> MAINTAINER_MODE_TRUE='#' MAKEINFO='${SHELL}
> /d/Libraries_For_C_and_C++/gmp-6.1.2/missing makeinfo'
> MANIFEST_TOOL='' MKDIR_P='/bin/mkdir -p' NM='' NMEDIT='' OBJDUMP=''
> OBJEXT='' OTOOL64='' OTOOL='' PACKAGE='gmp'
> PACKAGE_BUGREPORT='gmp-bugs#gmplib.org, see
> https://gmplib.org/manual/Reporting-Bugs.html' PACKAGE_NAME='GNU MP'
> PACKAGE_STRING='GNU MP 6.1.2' PACKAGE_TARNAME='gmp'
> PACKAGE_URL='http://www.gnu.org/software/gmp/' PACKAGE_VERSION='6.1.2'
> PATH_SEPARATOR=':' RANLIB='' SED='' SET_MAKE='' SHELL='/bin/sh'
> SPEED_CYCLECOUNTER_OBJ='pentium.lo' STRIP='' TAL_OBJECT=''
> TUNE_LIBS='' TUNE_SQR_OBJ='' U_FOR_BUILD='' VERSION='6.1.2'
> WANT_CXX_FALSE='' WANT_CXX_TRUE='' WITH_READLINE_01='' YACC=''
> YFLAGS='' ac_ct_AR='' ac_ct_CC='' ac_ct_CXX='' ac_ct_DUMPBIN=''
> am__EXEEXT_FALSE='' am__EXEEXT_TRUE='' am__isrc='' am__leading_dot='.'
> am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'
> bindir='${exec_prefix}/bin' build='i686-pc-mingw32' build_alias=''
> build_cpu='i686' build_os='mingw32' build_vendor='pc'
> datadir='${datarootdir}' datarootdir='${prefix}/share'
> docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' dvidir='${docdir}'
> exec_prefix='NONE' gmp_srclinks='' host='i686-pc-mingw32'
> host_alias='' host_cpu='i686' host_os='mingw32' host_vendor='pc'
> htmldir='${docdir}' includedir='${prefix}/include'
> infodir='${datarootdir}/info' install_sh='${SHELL}
> /d/Libraries_For_C_and_C++/gmp-6.1.2/install-sh'
> libdir='${exec_prefix}/lib' libexecdir='${exec_prefix}/libexec'
> localedir='${datarootdir}/locale' localstatedir='${prefix}/var'
> mandir='${datarootdir}/man' mkdir_p='$(MKDIR_P)' mpn_objects=''
> mpn_objs_in_libgmp='' oldincludedir='/usr/include' pdfdir='${docdir}'
> prefix='/d/Libraries_For_C_and_C++/GMP'
> program_transform_name='s,x,x,' psdir='${docdir}'
> sbindir='${exec_prefix}/sbin' sharedstatedir='${prefix}/com'
> sysconfdir='${prefix}/etc' target_alias=''
>
> ## ----------- ##
> ## confdefs.h. ##
> ## ----------- ##
>
> /* confdefs.h */
> #define PACKAGE_NAME "GNU MP"
> #define PACKAGE_TARNAME "gmp"
> #define PACKAGE_VERSION "6.1.2"
> #define PACKAGE_STRING "GNU MP 6.1.2"
> #define PACKAGE_BUGREPORT "gmp-bugs#gmplib.org, see https://gmplib.org/manual/Reporting-Bugs.html"
> #define PACKAGE_URL "http://www.gnu.org/software/gmp/"
> #define PACKAGE "gmp"
> #define VERSION "6.1.2"
> #define WANT_FFT 1
> #define HAVE_HOST_CPU_i686 1
>
> configure: exit 1
What can I do?
Thanks!
I fixed the error by updating the MinGW compilator.
I also found this guide if someone need it:
https://hyperactve.blogspot.com/2012/04/gmp-c-library-in-windows-mingwmsys.html
I wrote a following simple code:
time_t makeUnixTimeStamp( int year, int month, int day, int hour, int min, int sec ) {
tm uts_time;
uts_time.tm_year = year - 1900;
uts_time.tm_mon = month - 1;
uts_time.tm_mday = day;
uts_time.tm_sec = sec;
uts_time.tm_min = min;
uts_time.tm_hour = hour;
return mktime( &uts_time );
}
std::string getReadableDateTime( unsigned int unixTimeStamp ) {
char dateTime[ 40 ];
time_t someTime = unixTimeStamp;
struct tm *mTime;
mTime = localtime( &someTime );
strftime( dateTime, sizeof( dateTime ), "%Y-%m-%d %H:%M:%S", mTime );
return std::string( dateTime );
}
unsigned int startLogTime = makeUnixTimeStamp( 2016, 05, 04, 00, 00, 00 );
time_t nowTime;
time( &nowTime );
std::cout << "readable Time = " << getReadableDateTime( startLogTime ) << '\n';
I get strange output after a few runs. I do php -r 'echo time();' for show current second.
Why have I different "readable time" if I don't change anything in my code?
Output:
15:20:58 ~ $ rm a.out && g++ analyze.cpp && ./a.out && php -r 'echo time();'
readable Time = 2016-05-04 00:00:00
1462450865
15:21:05 ~ $ rm a.out && g++ analyze.cpp && ./a.out && php -r 'echo time();'
readable Time = 2016-05-04 00:00:00
1462450866
15:21:06 ~ $ rm a.out && g++ analyze.cpp && ./a.out && php -r 'echo time();'
readable Time = 2016-05-04 00:00:00
1462450867
15:21:07 ~ $ rm a.out && g++ analyze.cpp && ./a.out && php -r 'echo time();'
readable Time = 2016-05-03 23:00:00
1462450868
15:21:08 ~ $ rm a.out && g++ analyze.cpp && ./a.out && php -r 'echo time();'
readable Time = 2016-05-03 23:00:00
1462450869
15:21:09 ~ $ rm a.out && g++ analyze.cpp && ./a.out && php -r 'echo time();'
readable Time = 2016-05-04 00:00:00
1462450871
15:21:11 ~ $ rm a.out && g++ analyze.cpp && ./a.out && php -r 'echo time();'
readable Time = 2016-05-03 23:00:00
1462450872
15:21:12 ~ $ rm a.out && g++ analyze.cpp && ./a.out && php -r 'echo time();'
readable Time = 2016-05-04 00:00:00
1462450877
15:21:17 ~ $ rm a.out && g++ analyze.cpp && ./a.out && php -r 'echo time();'
readable Time = 2016-05-04 00:00:00
1462450882
15:21:22 ~ $ rm a.out && g++ analyze.cpp && ./a.out && php -r 'echo time();'
readable Time = 2016-05-03 23:00:00
1462450883
Seems that if I remove time() function - it works better but I need it after that code.
You should set the DST flag. It is probably being randomly initialized
The Daylight Saving Time flag (tm_isdst) is greater than zero if Daylight Saving Time is in effect, zero if Daylight Saving Time is not in effect, and less than zero if the information is not available.
http://www.cplusplus.com/reference/ctime/tm/
A useful recipe is to fist initialize the tm structure with the current local time, so that this gets set the same way as everything else on your machine.
time_t now = time(0);
uts_time = * localtime( &now );
// initialise with the time you really want
You have some uninitialised parts of your tm structure: the behaviour on reading back any uninitialised portion is undefined.
Use code like tm foo{}; instead which causes all structure elements to be initialised with zero values (and pointers to null pointer values).
I have a project that contains C and C++ files and I created a Makefile to compile this project.
Is it possible to have a Makefile that will "separate" the C and C++ files, the C files will be compile with gcc and the C++ files with g++ and create one binary ?
This is the Makefile I created:
TECHAUDIO_ROOT = ../../../../../../..
TECHAUDIO_GENERIC = $(TECHAUDIO_ROOT)/Generic
TECHAUDIO_MALLOC_3DSL = $(TECHAUDIO_ROOT)/Tools/Malloc_3DSL
TECHAUDIO_SIGPROC_COMMON_SRC = ../../../../SignalProcessing/RefFT/Common/src
TECHAUDIO_SIGPROC_SRC = ../../../../SignalProcessing/RefFT/Float/src
TECHAUDIO_LIMOTOR_SRC = ../../../RefFT/Float/src
TECHAUDIO_LIMOTOR_COMMON_SRC = ../../../RefFT/Common/src/API
INCLUDES += -I$(TECHAUDIO_GENERIC)/Common/Include \
-I$(TECHAUDIO_GENERIC)/X86/Include \
-I$(TECHAUDIO_MALLOC_3DSL)/RefFT/Common/Include \
-I$(TECHAUDIO_SIGPROC_COMMON_SRC) \
-I$(TECHAUDIO_SIGPROC_SRC)/Math \
-I$(TECHAUDIO_SIGPROC_SRC)/Transform \
-I$(TECHAUDIO_SIGPROC_SRC)/Filter \
-I$(TECHAUDIO_SIGPROC_SRC)/Vector \
-I$(TECHAUDIO_SIGPROC_SRC)/SSTP \
-I$(TECHAUDIO_LIMOTOR_SRC)/API \
-I$(TECHAUDIO_LIMOTOR_COMMON_SRC) \
-I$(TECHAUDIO_LIMOTOR_SRC)
SRCS = $(TECHAUDIO_LIMOTOR_SRC)/LIMITOR_main_32f.c \
$(TECHAUDIO_LIMOTOR_SRC)/API/LIMITOR_API_32f.c \
$(TECHAUDIO_LIMOTOR_SRC)/API/LIMITOR_API_coordinate_32f.c
SRCSCPP = $(TECHAUDIO_LIMOTOR_SRC)/Test/LIMITOR_TEST_example_32f.cpp
# $(TECHAUDIO_LIMOTOR_SRC)/VST/LIMITOR_VST_audioEffect_32f.cpp \
# $(TECHAUDIO_LIMOTOR_SRC)/VST/LIMITOR_VST_main_32f.cpp
NAME = Bonjour
CC = gcc
CPP = g++
CFLAGS += $(INCLUDES)
CFLAGS += -D_X86_GCC_4_1_1_TARGET_
#CFLAGS +=-D_X86_VC8_TARGET_
RM = rm -f
OBJ= $(SRCS:.c=.o)
OBJCPP= $(SRCSCPP:.cpp=.o)
all: $(NAME)
$(NAME): $(OBJ)
$(CC) $(CFLAGS) $(OBJ) -o $(NAME) -lm
$(OBJCPP)
$(CPP) $(CFLAGS) $(OBJCPP) -o $(NAME) -lm
clean:
$(RM) $(OBJ) $(OBJCPP)
fclean: clean
$(RM) $(NAME)
re: fclean all
EDIT
Below is an updated version of the Makefile:
TECHAUDIO_ROOT = ../../../../../../..
TECHAUDIO_GENERIC = $(TECHAUDIO_ROOT)/Generic
TECHAUDIO_MALLOC_3DSL = $(TECHAUDIO_ROOT)/Tools/Malloc_3DSL
TECHAUDIO_SIGPROC_COMMON_SRC = ../../../../SignalProcessing/RefFT/Common/src
TECHAUDIO_SIGPROC_SRC = ../../../../SignalProcessing/RefFT/Float/src
TECHAUDIO_LIMOTOR_SRC = ../../../RefFT/Float/src
TECHAUDIO_LIMOTOR_COMMON_SRC = ../../../RefFT/Common/src/API
INCLUDES += -I$(TECHAUDIO_GENERIC)/Common/Include \
-I$(TECHAUDIO_GENERIC)/X86/Include \
-I$(TECHAUDIO_MALLOC_3DSL)/RefFT/Common/Include \
-I$(TECHAUDIO_SIGPROC_COMMON_SRC) \
-I$(TECHAUDIO_SIGPROC_SRC)/Math \
-I$(TECHAUDIO_SIGPROC_SRC)/Transform \
-I$(TECHAUDIO_SIGPROC_SRC)/Filter \
-I$(TECHAUDIO_SIGPROC_SRC)/Vector \
-I$(TECHAUDIO_SIGPROC_SRC)/SSTP \
-I$(TECHAUDIO_LIMOTOR_SRC)/API \
-I$(TECHAUDIO_LIMOTOR_COMMON_SRC) \
-I$(TECHAUDIO_LIMOTOR_SRC)
SRCS = $(TECHAUDIO_LIMOTOR_SRC)/LIMITOR_main_32f.c \
$(TECHAUDIO_LIMOTOR_SRC)/API/LIMITOR_API_32f.c \
$(TECHAUDIO_LIMOTOR_SRC)/API/LIMITOR_API_coordinate_32f.c
SRCSCPP = $(TECHAUDIO_LIMOTOR_SRC)/Test/LIMITOR_TEST_example_32f.cpp
# $(TECHAUDIO_LIMOTOR_SRC)/VST/LIMITOR_VST_audioEffect_32f.cpp \
# $(TECHAUDIO_LIMOTOR_SRC)/VST/LIMITOR_VST_main_32f.cpp
NAME = Bonjour
CC = gcc
CPP = g++
CFLAGS += $(INCLUDES)
CFLAGS += -D_X86_GCC_4_1_1_TARGET_
#CFLAGS +=-D_X86_VC8_TARGET_
RM = rm -f
OBJ= $(SRCS:.c=.o)
OBJCPP= $(SRCSCPP:.cpp=.o)
%.o: %.c
$(CC) $(CFLAGS) $<
%.o: %.cpp
$(CPP) $(CFLAGS) $<
all: $(NAME)
$(NAME): $(OBJ) $(OBJCPP)
$(LD) $^ -o $# $(LDFLAGS)
clean:
$(RM) $(OBJ) $(OBJCPP)
fclean: clean
$(RM) $(NAME)
re: fclean all
These are the errors I receive when I execute make:
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 20 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 21 a un index de symbole 22 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_line): réadressage 0 a un index de symbole 2 invalide
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o: dans la fonction « _start »:
(.text+0x18): référence indéfinie vers « main »
/tmp/ccvLa3z6.o: dans la fonction « LIMITOR_3DSL_getStatusSize_32f »:
LIMITOR_main_32f.c:(.text+0x1e): référence indéfinie vers « MALLOC_3DSL_compute_memory_size_align_heap »
Try adding these rules:
%.o: %.c
$(CC) $(CFLAGS) $<
%.o: %.cpp
$(CPP) $(CFLAGS) $<
And changing your main line to:
$(NAME): $(OBJ) $(OBJCPP)
$(LD) $^ -o $# $(LDFLAGS)
EDIT:
Here is an attempt to integrate this in your code. I did not run this, though.
TECHAUDIO_ROOT = ../../../../../../..
TECHAUDIO_GENERIC = $(TECHAUDIO_ROOT)/Generic
TECHAUDIO_MALLOC_3DSL = $(TECHAUDIO_ROOT)/Tools/Malloc_3DSL
TECHAUDIO_SIGPROC_COMMON_SRC = ../../../../SignalProcessing/RefFT/Common/src
TECHAUDIO_SIGPROC_SRC = ../../../../SignalProcessing/RefFT/Float/src
TECHAUDIO_LIMOTOR_SRC = ../../../RefFT/Float/src
TECHAUDIO_LIMOTOR_COMMON_SRC = ../../../RefFT/Common/src/API
INCLUDES += -I$(TECHAUDIO_GENERIC)/Common/Include \
-I$(TECHAUDIO_GENERIC)/X86/Include \
-I$(TECHAUDIO_MALLOC_3DSL)/RefFT/Common/Include \
-I$(TECHAUDIO_SIGPROC_COMMON_SRC) \
-I$(TECHAUDIO_SIGPROC_SRC)/Math \
-I$(TECHAUDIO_SIGPROC_SRC)/Transform \
-I$(TECHAUDIO_SIGPROC_SRC)/Filter \
-I$(TECHAUDIO_SIGPROC_SRC)/Vector \
-I$(TECHAUDIO_SIGPROC_SRC)/SSTP \
-I$(TECHAUDIO_LIMOTOR_SRC)/API \
-I$(TECHAUDIO_LIMOTOR_COMMON_SRC) \
-I$(TECHAUDIO_LIMOTOR_SRC)
SRCS = $(TECHAUDIO_LIMOTOR_SRC)/LIMITOR_main_32f.c \
$(TECHAUDIO_LIMOTOR_SRC)/API/LIMITOR_API_32f.c \
$(TECHAUDIO_LIMOTOR_SRC)/API/LIMITOR_API_coordinate_32f.c
SRCSCPP = $(TECHAUDIO_LIMOTOR_SRC)/Test/LIMITOR_TEST_example_32f.cpp
# $(TECHAUDIO_LIMOTOR_SRC)/VST/LIMITOR_VST_audioEffect_32f.cpp \
# $(TECHAUDIO_LIMOTOR_SRC)/VST/LIMITOR_VST_main_32f.cpp
NAME = Bonjour
CC = gcc -c
CPP = g++ -c
LD = g++ -o
CFLAGS += $(INCLUDES)
CFLAGS += -D_X86_GCC_4_1_1_TARGET_
#CFLAGS +=-D_X86_VC8_TARGET_
RM = rm -f
OBJ= $(SRCS:.c=.o)
OBJCPP= $(SRCSCPP:.cpp=.o)
%.o: %.c
$(CC) $< -o $# $(CFLAGS)
%.o: %.cpp
$(CPP) $< -o $# $(CFLAGS)
all: $(NAME)
$(NAME): $(OBJ) $(OBJCPP)
$(LD) $# $^ -lm
clean:
$(RM) $(OBJ) $(OBJCPP)
fclean: clean
$(RM) $(NAME)
re: fclean all
I'm trying to test my homework (knapsack problem) and it's getting repetitive entering all these inputs every time I recompile.
Here's what I've got:
will#will-mint ~/code/byun-sp15 $ g++ knapsack.cpp
will#will-mint ~/code/byun-sp15 $ ./a.out
Please enter number of items: 3
Please enter Knapsack Capacity: 10
Enter weights and values of 3 items:
Item 1: 3 40
Item 2: 2 10
Item 3: 5 50
0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 * 0 *
0 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 *
0 * 50 * 50 * 99 * 50 * 50 * 60 * 60 * 60 * 60 *
Clearly my table is not correct, please do not help me there. NO SPOILERS!
I put 3 10 3 40 2 10 5 50 in test.txt and tried the following:
will#will-mint ~/code/byun-sp15 $ vim test.txt
will#will-mint ~/code/byun-sp15 $ test.txt > ./a.out
test.txt: command not found
will#will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out
will#will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out >> output.log
will#will-mint ~/code/byun-sp15 $ vim output.log
will#will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out 2> output.log
will#will-mint ~/code/byun-sp15 $ vim output.log
will#will-mint ~/code/byun-sp15 $ ./a.out < test.txt
will#will-mint ~/code/byun-sp15 $ cat test.txt | ./a.out > output.log
will#will-mint ~/code/byun-sp15 $ vim output.log
will#will-mint ~/code/byun-sp15 $ ./a.out << test.txt
None of which worked. I need help with my bash-fu, how can I use a string of space-separated numbers in a text file as input for my a.out?
This question already has answers here:
Unix sort of version numbers
(7 answers)
Closed 9 years ago.
I've got a few folders
src/1.0.0.1/
src/1.0.0.2/
src/1.0.0.12/
src/1.0.0.13/
src/1.0.1.1/
I'm looking for a bash command-chain that always returns only the latest version.
In the upper case that would be 1.0.1.1. If 1.0.1.1 wasn't present the latest version would be 1.0.0.13
I'm on OS X so sort has no -V option.
Can anyone help me out here?
You can also use an awk script:
#!/usr/bin/awk -f
$0 ~ /[0-9]+(.[0-9]+)*\/?$/ {
t = $0
sub(/\/$/, "", t)
sub(/.*\//, "", t)
current_count = split(t, current_array, /\./)
is_later = 0
for (i = 1; i <= current_count || i <= latest_count; ++i) {
if (current_array[i] > latest_array[i]) {
is_later = 1
break
} else if (latest_array[i] > current_array[i]) {
break
}
}
if (is_later) {
latest_string = $0
latest_count = split(t, latest_array, /\./)
}
}
END {
if (latest_count) {
print latest_string
}
}
Run:
find src/ -maxdepth 1 -type d | awk -f script.awk ## Or
ls -1 src/ | awk -f script.awk
You can also use a minimized version:
... | awk -- '$0~/[0-9]+(.[0-9]+)*\/?$/{t=$0;sub(/\/$/,"",t);sub(/.*\//,"",t);c=split(t,a,/\./);l=0;for(i=1;i<=c||i<=z;++i){if(a[i]>x[i]){l=1;break}else if(x[i]>a[i])break}if(l){s=$0;z=split(t,x,/\./)}}END{if(z)print s}'
Use sort (the -V option performs version sort):
$ ls -1 src/
1.0.0.1
1.0.0.12
1.0.0.13
1.0.0.2
$ find src/1* -type d | sort -rV
src/1.0.0.13
src/1.0.0.12
src/1.0.0.2
src/1.0.0.1
$ mkdir src/1.0.1.1
$ find src/1* -type d | sort -rV
src/1.0.1.1
src/1.0.0.13
src/1.0.0.12
src/1.0.0.2
src/1.0.0.1
Pipe the output to head and you can get only the highest version:
$ find src/1* -type d | sort -rV | head -1
src/1.0.1.1