llvm-link: error : expected top-level entity - llvm

I'm trying to compile the libpng 1.2.56 file and use a target.cc(same as fuzzer-test-suite to unite all these file in libpng1.2.56 into one LLVM IR bitcode file, named combined.bc.
Here is my compile process, refering build.sh:
[ ! -e libpng-1.2.56.tar.gz ] && wget https://downloads.sourceforge.net/project/libpng/libpng12/older-releases/1.2.56/libpng-1.2.56.tar.gz
[ ! -e libpng-1.2.56 ] && tar xf libpng-1.2.56.tar.gz
build_lib() {
rm -rf BUILD
cp -rf libpng-1.2.56 BUILD
(cd BUILD && ./configure --disable-shared && make -j $JOBS )
}
build_lib || exit 1
mkdir bitcode
clang++-10 -g -flto -std=c++11 ./target.cc -c -o bitcode/target.o -I .
cd bitcode
ar x ../.libs/libpng12.a
llvm-link-10 *.o -o combined.bc
And error is
enter image description here
The bitcode folder:
enter image description here
For modifications like the above, I succeeded on the project json, but not on libpng.
I am a beginner in LLVM and would like to get answers from you all. Thanks a lot!

Related

How do you compile ImGui on Windows vscode MinGW?

Right, so I have been trying for weeks now to get ImGui to work with my windows OpenGL project. I have tried everything. So, can someone please show me how to compile ImGui with the rest of my project. Like how to add it to the vs code task file or how to add it to my makefile. Also when I have asked before people have said use CMake. But I can't because CMake doesn't work so I can't use it and I don't want to waste more time to try and get it to work. So, anyone who knows how to help please do.
Here is my makefile:
CXX = g++
Flags = -std=c++17 -Wall -Wformat
Libs = -lGL -lGLEW -lglfw -ldl
OBJDIR = obj
VSXFLAGS = src/vendor/imgui/imgui_impl_glfw.h src/vendor/imgui/imgui_impl_opengl3.h
Filez = src/Rendering/*.cpp src/Rendering/*.h src/Core/*.h src/Core/*.cpp src/vendor/glm/gtc/type_ptr.hpp
Includes = -Isrc/PCH/ -Isrc/ -Iinclude/ -Isrc/Rendering/Buffers/ -Isrc/Core/ -Isrc/Rendering/ -Isrc/vendor/imgui -Isrc/FileManagement/ -Ires/ -Isrc/vendor/glm/ -Isrc/vendor/stb_image -Isrc/vendor/
all: main.cpp
$(CXX) $(Flags) $(Includes) $(Filez) main.cpp lib/imgui.a lib/Buffers.a -o main $(Libs)
clean:
rm $(OBJDIR)/*.o *.o
This is my file structure:
[]2
As ImGui is a separate library your project should link against it rather than compiling it with the rest of your project each time.
Here's how I build the library (both static and shared) in MSYS2 shell:
# change the next value to where you want to install it
export INSTALLPREFIX=/D/Prog/3rdparty
# fix DLL exports in imgui.h
mv imgui.h imgui.h.bak
cat > imgui.h << EOF
#if !defined(IMGUI_API) && defined(_WIN32)
#if defined(BUILD_IMGUI_SHARED)
#define IMGUI_API __declspec(dllexport)
#elif !defined(STATIC) && !defined(STATIC_IMGUI)
#define IMGUI_API __declspec(dllimport)
#else
#define IMGUI_API
#endif
#endif
EOF
sed -e "s/static char\s*EmptyString/IMGUI_API &/" imgui.h.bak >> imgui.h
# don't export inline functions in imgui_internal.h (version >= 1.81)
sed -i.bak -e "s/IMGUI_API \(~*ImGuiTable()\)/\1/" imgui_internal.h
~/buildstatus.sh build &&
touch SUCCESS &&
for F in *.cpp; do
echo CXX $F &&
g++ -O3 -I. $F -c -o $F.o -DBUILD_IMGUI_SHARED || rm -f SUCCESS
done &&
ls -1 SUCCESS > /dev/null &&
ar cru libimgui.a *.cpp.o &&
( echo EXPORTS; nm -f posix --defined-only -p libimgui.a | sed -n -e "s/^\([^ ]*\) T .*$/\1/p" | sed -e "s/^__*/_/" | grep "Im" ) > imgui.def &&
g++ -shared -s -mwindows -def imgui.def -o imgui.dll libimgui.a -Wl,--out-implib,libimgui.dll.a -Wl,--as-needed -limm32 &&
~/buildstatus.sh install &&
mkdir -p $INSTALLPREFIX/include/imgui $INSTALLPREFIX/lib $INSTALLPREFIX/bin &&
cp -f *.cpp *.h $INSTALLPREFIX/include/imgui/ &&
cp -f *.a $INSTALLPREFIX/lib/ &&
cp -f *.dll $INSTALLPREFIX/bin/ &&
echo SUCCESS
Make sure your MSYS2 environment points to the same compiler as VSCode in case its different (add to PATH).
My build was done with a recent standalone GCC/MinGW-w64 from https://winlibs.com/

VS Code Code Runner C++ with wrong command in terminal

I'm using Code Runner extension in VS Code to run C++ code and it's using the wrong terminal command to do so. I'm using git-bash in VS Code and Windows 10.
This is the command in terminal:
Douglas#LAPTOP-6BSNLLDB MINGW64 /c/path (master)
$ cd "c:\path\" && g++ HelloWorld.cpp -o HelloWorld && "c:\path\"HelloWorld
bash: cd: c:\path" && g++ HelloWorld.cpp -o HelloWorld && c:path"HelloWorld: No such file or directory
As you can see, it's using cd and g++ correctly, but the command to actually run the .exe file is wrong.
Shouldn't it be "c:\path\HellowWorld.exe"?
How can I change this? It works correctly with python.
If I can't, how do I run C++ code within VS Code?
Seems like you are using git-bash instead of PowerShell.
you only need to use
"code-runner.terminalRoot": "/",
VSCode: Code Runner extension is unable to execute the code on git bash terminal?
Change setting to
"code-runner.executorMap":{
"cpp": "cd $dirWithoutTrailingSlash && g++ $fileName -o $fileNameWithoutExt && ./$fileNameWithoutExt",
}
also c's: ( I use tcc)
"code-runner.executorMap":{
"c": "cd $dirWithoutTrailingSlash && tcc -run $fileNameWithoutExt.c",
}
$ cd /d "c:\path\" && g++ HelloWorld.cpp -o HelloWorld && HelloWorld
Or..
$ cd /d "c:\path\" && g++ HelloWorld.cpp -o HelloWorld.exe && HelloWorld
What wuyudi said before isn't false, but I think instead of
"code-runner.termnalRoot":"/",
you should use
"code-runner.terminalRoot":"/mnt/"
it's working fine for me so I hope it will work for the others too.

Launch tests normally when not in debug mode

For my C++ project have the following Makefile:
GDB=gdb
DEBUG ?= 1
ifeq ($(DEBUG), 1)
CCFLAGS =-DDEBUG
RUNPATH =${GDB}
else
CCFLAGS=-DNDEBUG
RUNPATH="/bin/sh -c"
endif
CPP=g++ ${CCFLAGS}
TESTGEN=cxxtestgen
CFLAGS_DBG=""
TEST_BUILD_PATH="./build/tests"
BUILD_PATH="./build"
TESTS_SRC_PATH="./tests"
SRC_PATH=""
# NORMAL TARGETS
# To Be filled
# RUN TESTS
test_command_parser_gen:
${TESTGEN} --error-printer -o ${TESTS_SRC_PATH}/CommandParser/runner.cpp ./tests/CommandParser/testCommandParser.h
test_command_parser_build: test_command_parser_gen
${CPP} -o ${TEST_BUILD_PATH}/commandParser ${TESTS_SRC_PATH}/CommandParser/runner.cpp ./src/tools/command_parser.cpp
test_command_parser_run: test_command_parser_build
${RUNPATH} ./build/tests/commandParser
clean:
find ./build ! -name '.gitkeep' -type f -exec rm -f {} + && find ./tests ! -name *.h -type f -exec rm -f {} +
When I launch the tests via the command:
make test_command_parser_run
As expected the gdb fires up and I can use it to debug the test. But sometimes I need just to run the test as is (eg. when in CI) therefore I use the following command to do so:
make test_command_parser_run DEBUG=0
But in that case I get the following error:
cxxtestgen --error-printer -o "./tests"/CommandParser/runner.cpp ./tests/CommandParser/testCommandParser.h
g++ -DNDEBUG -o "./build/tests"/commandParser "./tests"/CommandParser/runner.cpp ./src/tools/command_parser.cpp
"/bin/sh -c" ./build/tests/commandParser
/bin/sh: 1: /bin/sh -c: not found
Makefile:31: recipe for target 'test_command_parser_run' failed
make: *** [test_command_parser_run] Error 127
Therefore, I wanted to know how I can tell the make to execute the test without gdb when not in "debug" mode.
The whole idea behind this is somehow automatically debug my application without the need to remember the command and the compilation sequence to do so.
Remove quotes around /bin/sh -c, like so:
else
CCFLAGS=-DNDEBUG
RUNPATH=/bin/sh -c

tar compress with -C argument doesn't work

This set of commands aren't working as they're supposed to:
mkdir -p /home/git/root_backup_folder
cd /home/git/gitlab/git-data/repositories
tar zcvf dailybackup.tar.gz * -C /home/git/root_backup_folder
It is completely ignoring the -C argument and creating the file in /home/git/gitlab/git-data/repositories. What I'm doing wrong?
The -C flag doesn't specify the output directory. You need to do this at the point at which you specify the archive file. So, your command could become:
tar zcvf /home/git/root_backup_folder/dailybackup.tar.gz *

"ifort: no match" error in csh script

I'm trying to compile a program called ZEUS and I am following the included instructions exactly but I came across the following error.
The instructions asked me to type csh -v namelist.s in the folder containing namelist.s. This is a fairly large assembly file which invokes another file given in the source files called bldlibo which is the csh file mentioned in the title. The contents of this file are:
#==== SCRIPT TO BUILD AN OBJECT LIBRARY FROM A FORTRAN SOURCE FILE====#
#
# Syntax: bldlibo <library name> <source code>
# eg: bldlibo namelist.a namelist.f
#
rm -rf bldlibo.dir
mkdir bldlibo.dir
cp $2 bldlibo.dir
cd bldlibo.dir
fsplit $2 >& /dev/null
rm $2
#
# When -fast option is used, this leads to the __vsincos_ unsatisfied
# external errors when zeus is compiled with -g option. Thus, use -O4
# instead.
#
ifort -c -O4 *.f
#f77 -c -g -C -ftrap=common *.f
ar rv $1 *.o >& /dev/null
ranlib $1
cd ..
mv bldlibo.dir/$1 .
rm -r bldlibo.dir
When I run csh -v namelist.s it begins to run bldlibo and works fine up until ifort is invoked at which point it says ifort: no match. I have tried adding #!/bin/csh at the start and also source .../ifortvars.csh but that didn't work.
Can anybody help me, sorry if I haven't explained it well enough.