How can I make C compiler find the folder? - c

I have an error message while building my C program:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [../bin/hannimpeha] Error 1
make[2]: *** [CMakeFiles/hannimpeha.dir/all] Error 2
make[1]: *** [CMakeFiles/hannimpeha.dir/rule] Error 2
make: *** [hannimpeha] Error 2
My cmake file goes like
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/cmake-build-debug)
add_executable(hannimpeha ${PROJECT_SOURCE_DIR}/bin/OLED_main.c)
How can I make C compiler find the right path?

Related

Linux compilation throwing error header file error

I am compiling this code (minimul linux kernel) from https://github.com/liva/minimal-linux
I am getting > make[1]: *** [Kbuild:42: include/generated/timeconst.h] Error 127
basically its make error. may be error in timeconst.h or may be its missing file.
So my question is how to find the file in the minimul-linux-master (download from above link) folder and how to debug for more info when compiling the code.
as u can see what make displays is completely useless. And I have no clue why the error is caused. there are not any other errors so I assumed all the errors or single error is in timeconst.h.
this is terminal output.
....
HOSTCC scripts/mod/sumversion.o
HOSTLD arch/x86/tools/relocs
HOSTCC scripts/mod/file2alias.o
UPD include/config/kernel.release
CHK include/generated/utsrelease.h
UPD include/generated/utsrelease.h
CC kernel/bounds.s
CHK include/generated/timeconst.h
/bin/sh: 1: bc: not found
make[1]: *** [Kbuild:42: include/generated/timeconst.h] Error 127
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1054: prepare0] Error 2
make: *** Waiting for unfinished jobs....
HOSTLD scripts/mod/modpost
I am on host: 5.10.0-kali3-amd64
machine is x86-64
I fixed the same by comparing mine KBuild with the one defined in in the given link.
https://android.googlesource.com/kernel/msm/+/db248780101f2ca2bc3c02598917e88dfdce3207/Kbuild

How to fix 'ld: library not found for -lglib-2.0'

I have to do a compiler with flex and bison for a school project.
They give to me example of new language but I can't compile them..
The code is working fine for other people so the problem come from my Mac. The problem appears when I try to compile with make command, he say "ld: library not found for -lglib-2.0".
I installed "Glib" already but this don't solve the problem.
make
[ 20%] Linking C executable facile
ld: library not found for -lglib-2.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [facile] Error 1
make[1]: *** [CMakeFiles/facile.dir/all] Error 2
make: *** [all] Error 2
I need to compile the code to work after on the project.
Thanks you

Cannot open output file : Is a directory collect2: ld returned 1 exit status

I am using CLion code editor.
I have such structure of project:
This is the content of CMakeLists.txt:
cmake_minimum_required(VERSION 3.4)
project(FirstAgent)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.c)
add_executable(FirstAgent ${SOURCE_FILES})
target_link_libraries(FirstAgent simgrid)
But when I run my program in the code editor the error occur:
/usr/bin/ld: cannot open output file FirstAgent: Is a directory
collect2: error: ld returned 1 exit status
make[3]: *** [FirstAgent] Error 1
make[2]: *** [CMakeFiles/FirstAgent.dir/all] Error 2
make[1]: *** [CMakeFiles/FirstAgent.dir/rule] Error 2
make: *** [FirstAgent] Error 2
How can I avoid it?
You can try setting an output directory, so that the binaries are stored elsewhere:
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)

MacPorts linker (ld) not found

I'm trying to compile cgminer on Mac, and the compilation cannot complete, citing "ld: library not found for -lrt"
Exact terminal output:
CCLD cgminer
ld: library not found for -lrt
collect2: ld returned 1 exit status
make[1]: *** [cgminer] Error 1
make: *** [install-recursive] Error 1
Any solution for how to install the linker library via command line?

Error Building Clang

I am trying to build Clang on Linux (Amazon's EC2). I am running the make as per the guide at:
http://clang.llvm.org/get_started.html
I am getting the following link error messages:
llvm[2]: Linking Debug+Asserts executable opt
/home/ec2-user/benchmark/build/tools/opt/Debug+Asserts/opt.o: In function `llvm::ParseIR(llvm::MemoryBuffer*, llvm::SMDiagnostic&, llvm::LLVMContext&)':
opt.cpp:(.text._ZN4llvm7ParseIREPNS_12MemoryBufferERNS_12SMDiagnosticERNS_11LLVMContextE[llvm::Pars eIR(llvm::MemoryBuffer*, llvm::SMDiagnostic&, llvm::LLVMContext&)]+0x5f): undefined reference to `llvm::ParseBitcodeFile(llvm::MemoryBuffer*, llvm::LLVMContext&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
collect2: ld returned 1 exit status
make[2]: *** [/home/ec2-user/benchmark/build/Debug+Asserts/bin/opt] Error 1
make[2]: Leaving directory `/home/ec2-user/benchmark/build/tools/opt'
make[1]: *** [opt/.makeall] Error 2
make[1]: Leaving directory `/home/ec2-user/benchmark/build/tools'
make: *** [all] Error 1
Does anyone know what this means?
Edit: I rebuilt the entire project from svn and now I am getting the following error:
COMPILE: clang_linux/asan-i386/i386: /home/ec2-user/benchmark/llvm/projects/compiler-rt/lib/asan/asan_rtl.cc
/home/ec2-user/benchmark/llvm/projects/compiler-rt/lib/asan/asan_rtl.cc:28:10: fatal error: 'new' file not found
#include <new>
^
1 error generated.
make[5]: *** [/home/ec2-user/benchmark/build/tools/clang/runtime/compiler-rt/clang_linux/asan-i386/i386/SubDir.lib__asan/asan_rtl.o] Error 1
make[5]: Leaving directory `/home/ec2-user/benchmark/llvm/projects/compiler-rt'
make[4]: *** [BuildRuntimeLibraries] Error 2
make[4]: Leaving directory `/home/ec2-user/benchmark/build/tools/clang/runtime/compiler-rt'
make[3]: *** [compiler-rt/.makeall] Error 2
make[3]: Leaving directory `/home/ec2-user/benchmark/build/tools/clang/runtime'
make[2]: *** [all] Error 1
make[2]: Leaving directory `/home/ec2-user/benchmark/build/tools/clang'
make[1]: *** [clang/.makeall] Error 2
make[1]: Leaving directory `/home/ec2-user/benchmark/build/tools'
make: *** [all] Error 1
I followed this and I was able to build it successfully in the first shot itself.
I guess, you are hitting issues with your C++ standard library headers. So you need to follow the Step #6 in the above mentioned link!
Start a fresh build and please ensure that you satisfy this prerequisite.

Resources