Перемещение R_X86_64_32S против `.bss 'не может быть использовано при ошибке связывания PIE - PullRequest
0 голосов
/ 28 августа 2018

Я пытаюсь скомпилировать AccNEAT проект с поддержкой CUDA. Это работает нормально, когда я компилирую без поддержки CUDA. Однако, когда я компилирую с поддержкой CUDA, я получаю ошибки компоновщика. Для компиляции проекта моей средой является Ubuntu 18.04 LTS 64 bit с GCC-4.8 и NVCC 6.0.

Ошибка компоновщика:

/usr/bin/x86_64-linux-gnu-ld: obj/cu/network/cuda/cudanetwork.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/maze/mazeevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/static/staticevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:49: recipe for target 'neat' failed
make: *** [neat] Error 1

Компилятор предлагает добавить опцию -fPIC, но я не знаю точно, где поместить ее в Makefile. Я пытался добавить его, используя параметр -XCompiler, например -XCompiler "-fPIC...", но затем, когда я компилирую, я получаю эту ошибку:

obj/cu/cxx/experiments/maze/mazeevaluator.o: In function `NEAT::create_config(NEAT::Config*&, unsigned long&)':
/home/ner/Projekty/accneat-master-cuda/src/experiments/maze/mazeevaluator.cxx:158: undefined reference to `NEAT::find_resource(std::string const&)'
/home/ner/Projekty/accneat-master-cuda/src/experiments/maze/mazeevaluator.cxx:158: undefined reference to `NEAT::parse_map(std::string)'
collect2: error: ld returned 1 exit status
Makefile:49: recipe for target 'neat' failed
make: *** [neat] Error 1

Что означает ошибка «перемещение» и есть ли способ решить эту проблему?

Мой Makefile:

include Makefile.conf

CC_CUDA=nvcc -DENABLE_CUDA ${NVCC_FLAGS} -arch=sm_13 --debug --compiler-bindir ${PFM_NVCC_CCBIN} -Xcompiler "${OPT} ${INCLUDES} ${OPENMP} -I/usr/local/cuda/include "

INCLUDES=$(patsubst %,-I%,$(shell find src -type d))
SOURCES=$(shell find src -name "*.cpp")
CXX_SOURCES=$(shell find src -name "*.cxx")

OBJECTS=${SOURCES:src/%.cpp=obj/cpp/%.o}

LIBS=-lgomp
DEFINES=

ifeq (${ENABLE_CUDA}, true)
    CUDA_SOURCES=$(shell find src -name "*.cu")
    CUDA_OBJECTS=${CUDA_SOURCES:src/%.cu=obj/cu/%.o}
    CUDA_OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cu/cxx/%.o}
    LIBS+=-lcudart
    DEFINES+=-DENABLE_CUDA
else
    OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cpp/cxx/%.o}
endif

DEPENDS=${OBJECTS:%.o=%.d}
DEPENDS+=${CUDA_OBJECTS:%.o=%.d}

ifeq (${DEVMODE}, true)
    OPT=-O0
    #OPENMP=-fopenmp
    MISC_FLAGS=
    NVCC_FLAGS=-G -g
else
    OPT=-O3
    OPENMP=-fopenmp
    MISC_FLAGS=-Werror
endif

CC_FLAGS=-Wall ${DEFINES} ${MISC_FLAGS} ${PROFILE} ${INCLUDES} ${OPENMP} ${OPT} -c -g -gdwarf-3
.PHONY: clean default

default: ./neat

clean:
    rm -rf obj
    rm -f ./neat
    rm -f src/util/std.h.gch

./neat: ${OBJECTS} ${CUDA_OBJECTS}
    g++ ${PROFILE} ${OBJECTS} ${CUDA_OBJECTS} ${PFM_LD_FLAGS} ${LIBS} -o $@

src/util/std.h.gch: src/util/std.h Makefile.conf Makefile
    g++ ${CC_FLAGS} -std=c++11 $< -o $@

ifeq (${ENABLE_CUDA}, true)

obj/cu/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c -x cu $< -o $@

obj/cu/cxx/%.d: src/%.cxx
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M -x cu $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

obj/cu/%.o: src/%.cu Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c $< -o $@

obj/cu/%.d: src/%.cu
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

else
obj/cpp/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++98 -MMD $< -o $@
endif

obj/cpp/%.o: src/%.cpp Makefile.conf Makefile src/util/std.h.gch
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++11 -MMD $< -o $@

-include ${DEPENDS}

(я добавил небольшие изменения для его компиляции, например, include nvcc dir path).

Команда построения:

g++  obj/cpp/experiments/maze/maze.o obj/cpp/experiments/static/regex.o obj/cpp/experiments/static/cfg.o obj/cpp/experiments/static/xor.o obj/cpp/experiments/static/sequence.o obj/cpp/experiments/experiment.o obj/cpp/innovgenome/innovation.o obj/cpp/innovgenome/trait.o obj/cpp/innovgenome/innovnodegene.o obj/cpp/innovgenome/innovlinkgene.o obj/cpp/innovgenome/innovgenome.o obj/cpp/innovgenome/innovgenomemanager.o obj/cpp/genomemanager.o obj/cpp/population.o obj/cpp/network/cpu/cpunetwork.o obj/cpp/species/speciesorganism.o obj/cpp/species/species.o obj/cpp/species/speciespopulation.o obj/cpp/util/timer.o obj/cpp/util/rng.o obj/cpp/util/util.o obj/cpp/util/resource.o obj/cpp/util/map.o obj/cpp/main.o obj/cpp/organism.o obj/cpp/neat.o obj/cu/network/cuda/cudanetwork.o obj/cu/cxx/experiments/maze/mazeevaluator.o obj/cu/cxx/experiments/static/staticevaluator.o  -lgomp -lcudart -o neat

РЕДАКТИРОВАТЬ 1: добавлен полный журнал сборки:

nerexis@nerexis-GE70-0NC-GE70-0ND:~/Projekty/accneat-master-cuda$ make clean
rm -rf obj
rm -f ./neat
rm -f src/util/std.h.gch
nerexis@nerexis-GE70-0NC-GE70-0ND:~/Projekty/accneat-master-cuda$ make
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 src/util/std.h -o src/util/std.h.gch
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/maze/maze.cpp -o obj/cpp/experiments/maze/maze.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/regex.cpp -o obj/cpp/experiments/static/regex.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/cfg.cpp -o obj/cpp/experiments/static/cfg.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/xor.cpp -o obj/cpp/experiments/static/xor.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/sequence.cpp -o obj/cpp/experiments/static/sequence.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/experiment.cpp -o obj/cpp/experiments/experiment.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovation.cpp -o obj/cpp/innovgenome/innovation.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/trait.cpp -o obj/cpp/innovgenome/trait.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovnodegene.cpp -o obj/cpp/innovgenome/innovnodegene.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovlinkgene.cpp -o obj/cpp/innovgenome/innovlinkgene.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovgenome.cpp -o obj/cpp/innovgenome/innovgenome.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovgenomemanager.cpp -o obj/cpp/innovgenome/innovgenomemanager.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/genomemanager.cpp -o obj/cpp/genomemanager.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/population.cpp -o obj/cpp/population.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/network/cpu/cpunetwork.cpp -o obj/cpp/network/cpu/cpunetwork.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/species/speciesorganism.cpp -o obj/cpp/species/speciesorganism.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/species/species.cpp -o obj/cpp/species/species.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/species/speciespopulation.cpp -o obj/cpp/species/speciespopulation.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/timer.cpp -o obj/cpp/util/timer.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/rng.cpp -o obj/cpp/util/rng.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/util.cpp -o obj/cpp/util/util.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/resource.cpp -o obj/cpp/util/resource.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/map.cpp -o obj/cpp/util/map.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/main.cpp -o obj/cpp/main.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/organism.cpp -o obj/cpp/organism.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/neat.cpp -o obj/cpp/neat.o
nvcc -DENABLE_CUDA  -arch=sm_13 --debug --compiler-bindir gcc-4.8 -Xcompiler "-O3 -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -I/usr/local/cuda/include -L/usrlocal/cuda/lib64" -c src/network/cuda/cudanetwork.cu -o obj/cu/network/cuda/cudanetwork.o
nvcc -DENABLE_CUDA  -arch=sm_13 --debug --compiler-bindir gcc-4.8 -Xcompiler "-O3 -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -I/usr/local/cuda/include -L/usrlocal/cuda/lib64" -c -x cu src/experiments/maze/mazeevaluator.cxx -o obj/cu/cxx/experiments/maze/mazeevaluator.o
nvcc -DENABLE_CUDA  -arch=sm_13 --debug --compiler-bindir gcc-4.8 -Xcompiler "-O3 -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -I/usr/local/cuda/include -L/usrlocal/cuda/lib64" -c -x cu src/experiments/static/staticevaluator.cxx -o obj/cu/cxx/experiments/static/staticevaluator.o
g++  obj/cpp/experiments/maze/maze.o obj/cpp/experiments/static/regex.o obj/cpp/experiments/static/cfg.o obj/cpp/experiments/static/xor.o obj/cpp/experiments/static/sequence.o obj/cpp/experiments/experiment.o obj/cpp/innovgenome/innovation.o obj/cpp/innovgenome/trait.o obj/cpp/innovgenome/innovnodegene.o obj/cpp/innovgenome/innovlinkgene.o obj/cpp/innovgenome/innovgenome.o obj/cpp/innovgenome/innovgenomemanager.o obj/cpp/genomemanager.o obj/cpp/population.o obj/cpp/network/cpu/cpunetwork.o obj/cpp/species/speciesorganism.o obj/cpp/species/species.o obj/cpp/species/speciespopulation.o obj/cpp/util/timer.o obj/cpp/util/rng.o obj/cpp/util/util.o obj/cpp/util/resource.o obj/cpp/util/map.o obj/cpp/main.o obj/cpp/organism.o obj/cpp/neat.o obj/cu/network/cuda/cudanetwork.o obj/cu/cxx/experiments/maze/mazeevaluator.o obj/cu/cxx/experiments/static/staticevaluator.o  -lgomp -lcudart -o neat
/usr/bin/x86_64-linux-gnu-ld: obj/cu/network/cuda/cudanetwork.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/maze/mazeevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/static/staticevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:49: recipe for target 'neat' failed
make: *** [neat] Error 1

РЕДАКТИРОВАТЬ 2: Makefile

include Makefile.conf
CC_CUDA=nvcc -DENABLE_CUDA ${NVCC_FLAGS} -arch=sm_20 --debug --compiler-bindir ${PFM_NVCC_CCBIN} -Xcompiler "${OPT} ${INCLUDES} ${OPENMP} -I/usr/local/cuda/include -L/usr/local/cuda/lib64 "

INCLUDES=$(patsubst %,-I%,$(shell find src -type d))
SOURCES=$(shell find src -name "*.cpp")
CXX_SOURCES=$(shell find src -name "*.cxx")

OBJECTS=${SOURCES:src/%.cpp=obj/cpp/%.o}

LIBS=-lgomp
DEFINES=

ifeq (${ENABLE_CUDA}, true)
    CUDA_SOURCES=$(shell find src -name "*.cu")
    CUDA_OBJECTS=${CUDA_SOURCES:src/%.cu=obj/cu/%.o}
    CUDA_OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cu/cxx/%.o}
    LIBS+=-lcudart
    DEFINES+=-DENABLE_CUDA
else
    OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cpp/cxx/%.o}
endif

DEPENDS=${OBJECTS:%.o=%.d}
DEPENDS+=${CUDA_OBJECTS:%.o=%.d}

ifeq (${DEVMODE}, true)
    OPT=-O0
    #OPENMP=-fopenmp
    MISC_FLAGS=
    NVCC_FLAGS=-G -g
else
    OPT=-O3
    OPENMP=-fopenmp
    MISC_FLAGS=-Werror
    NVCC_FLAGS=--relocatable-device-code=true --dont-use-profile -ldir /usr/local/cuda/nvvm/libdevice 
endif

CC_FLAGS=-Wall ${DEFINES} ${MISC_FLAGS} ${PROFILE} ${INCLUDES} ${OPENMP} ${OPT} -c -g -gdwarf-3 -fPIC
.PHONY: clean default

default: ./neat

clean:
    rm -rf obj
    rm -f ./neat
    rm -f src/util/std.h.gch

./neat: ${OBJECTS} ${CUDA_OBJECTS}
    g++ ${PROFILE} ${OBJECTS} ${CUDA_OBJECTS} ${PFM_LD_FLAGS} -fPIC ${LIBS} -o $@

src/util/std.h.gch: src/util/std.h Makefile.conf Makefile
    g++ ${CC_FLAGS} -std=c++11 $< -o $@

ifeq (${ENABLE_CUDA}, true)

obj/cu/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c -x cu $< -o $@

obj/cu/cxx/%.d: src/%.cxx
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M -x cu $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

obj/cu/%.o: src/%.cu Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c $< -o $@

obj/cu/%.d: src/%.cu
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

else
obj/cpp/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++98 -MMD $< -o $@
endif

obj/cpp/%.o: src/%.cpp Makefile.conf Makefile src/util/std.h.gch
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++11 -MMD $< -o $@

-include ${DEPENDS}

Журнал сборки (только конец из-за ограничения длины):

g++  obj/cpp/experiments/maze/maze.o obj/cpp/experiments/static/regex.o obj/cpp/experiments/static/cfg.o obj/cpp/experiments/static/xor.o obj/cpp/experiments/static/sequence.o obj/cpp/experiments/experiment.o obj/cpp/innovgenome/innovation.o obj/cpp/innovgenome/trait.o obj/cpp/innovgenome/innovnodegene.o obj/cpp/innovgenome/innovlinkgene.o obj/cpp/innovgenome/innovgenome.o obj/cpp/innovgenome/innovgenomemanager.o obj/cpp/genomemanager.o obj/cpp/population.o obj/cpp/network/cpu/cpunetwork.o obj/cpp/species/speciesorganism.o obj/cpp/species/species.o obj/cpp/species/speciespopulation.o obj/cpp/util/timer.o obj/cpp/util/rng.o obj/cpp/util/util.o obj/cpp/util/resource.o obj/cpp/util/map.o obj/cpp/main.o obj/cpp/organism.o obj/cpp/neat.o obj/cu/network/cuda/cudanetwork.o obj/cu/cxx/experiments/maze/mazeevaluator.o obj/cu/cxx/experiments/static/staticevaluator.o  -fPIC -lgomp -lcudart -o neat
/usr/bin/x86_64-linux-gnu-ld: obj/cu/network/cuda/cudanetwork.o: relocation R_X86_64_32S against symbol `_ZTVN4NEAT11CudaNetworkE' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/maze/mazeevaluator.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/static/staticevaluator.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:50: recipe for target 'neat' failed
make: *** [neat] Error 1

РЕДАКТИРОВАТЬ 3: Мне удалось скомпилировать, когда я добавил опции -fPIC -shared в опцию -Xcompiler и CC_FLAGS и строку ./neat: g ++. Когда я запускаю скомпилированный двоичный файл, я получаю ошибку ошибки сегментации. Дополнительная информация из программы valgrind:

==14367== Jump to the invalid address stated on the next line
==14367==    at 0x1C296: ???
==14367==    by 0x12506B: operator<< <std::char_traits<char> > (ostream:561)
==14367==    by 0x12506B: cmp(NEAT::InnovationId const&, NEAT::InnovationId const&) [clone .part.5] (innovation.cpp:43)
==14367==  Address 0x1c296 is not stack'd, malloc'd or (recently) free'd
==14367== 
==14367== 
==14367== Process terminating with default action of signal 11 (SIGSEGV)
==14367==  Bad permissions for mapped region at address 0x1C296
==14367==    at 0x1C296: ???
==14367==    by 0x12506B: operator<< <std::char_traits<char> > (ostream:561)
==14367==    by 0x12506B: cmp(NEAT::InnovationId const&, NEAT::InnovationId const&) [clone .part.5] (innovation.cpp:43)
==14367== 

1 Ответ

0 голосов
/ 30 августа 2018

Изменение настройки CC_FLAGS (параметры компиляции) с:

CC_FLAGS=-Wall ${DEFINES} ${MISC_FLAGS} ${PROFILE} ${INCLUDES} ${OPENMP} ${OPT} -c -g -gdwarf-3

до:

CC_FLAGS=-Wall ${DEFINES} ${MISC_FLAGS} ${PROFILE} ${INCLUDES} ${OPENMP} ${OPT} -c -g -gdwarf-3 -fPIC

, вероятно, излечит эту конкретную ошибку связи.

...