This is my first question, so I'll try to explain everything about my problem. So, I had downloaded Clion to code my first C programs for my university degree. So, when I create a simple Hello World on C, I can run normally, but if I create a new program or a new hello world, the program fails with the following error on Clion:
> ====================[ Build | MeusCodigosC_2_0 | Debug ]======================== "C:\Program Files\JetBrains\CLion
> 2020.2.1\bin\cmake\win\bin\cmake.exe" --build "C:\Users\salom\CLionProjects\MeusCodigosC 2.0\cmake-build-debug"
> --target MeusCodigosC_2_0 -- -j 12 Scanning dependencies of target MeusCodigosC_2_0 [ 33%] Building C object
> CMakeFiles/MeusCodigosC_2_0.dir/AtividadeProducaoLabU2.c.obj [ 66%]
> Building C object CMakeFiles/MeusCodigosC_2_0.dir/HelloWorld.c.obj
> [100%] Linking C executable MeusCodigosC_2_0.exe
> c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe:
> CMakeFiles\MeusCodigosC_2_0.dir/objects.a(HelloWorld.c.obj): na
> função "main": C:/Users/salom/CLionProjects/MeusCodigosC
> 2.0/HelloWorld.c:7: múltiplas definições de "main"; CMakeFiles\MeusCodigosC_2_0.dir/objects.a(AtividadeProducaoLabU2.c.obj):C:/Users/salom/CLionProjects/MeusCodigosC
> 2.0/AtividadeProducaoLabU2.c:32: definido primeiro aqui collect2.exe: error: ld returned 1 exit status mingw32-make.exe[3]: ***
> [MeusCodigosC_2_0.exe] Error 1 mingw32-make.exe[2]: ***
> [CMakeFiles/MeusCodigosC_2_0.dir/all] Error 2 mingw32-make.exe[1]: ***
> [CMakeFiles/MeusCodigosC_2_0.dir/rule] Error 2 mingw32-make.exe: ***
> [MeusCodigosC_2_0] Error 2
> CMakeFiles\MeusCodigosC_2_0.dir\build.make:119: recipe for target
> 'MeusCodigosC_2_0.exe' failed CMakeFiles\Makefile2:94: recipe for
> target 'CMakeFiles/MeusCodigosC_2_0.dir/all' failed
> CMakeFiles\Makefile2:101: recipe for target
> 'CMakeFiles/MeusCodigosC_2_0.dir/rule' failed Makefile:137: recipe for
> target 'MeusCodigosC_2_0' failed
I checked my CMakeLists.txt which I read that it's the file that makes your codes run, and the new code was already added to the target, but I still can't run it. The only workaround I had found is to delete the old code that I'm not using, and leave it only the code I want to use in that specific moment, only then I can run my C codes on Clion. Anyone had already face an issue like this? Thank you!
The error message says (if I understand Portuguese correctly) that the compiled files have several main functions defined in them.
main() is the function that runs when your program is executed. Several functions with the same name mean that the compiler doesn't know which one you want to run.
If you are writing several different programs, just keep them in separate folders, or make sure your CMakeLists.txt includes only one of them.
UPD: It looks like CLion supports one project creating multiple executable files. See documentation.
In your case, CMakeFile.txt should probably contain two lines (file names might need to be corrected):
add_executable(hello_world HelloWorld.c)
add_executable(MeusCodigosC_2_0 AtividadeProducaoLabU2.c)
If HelloWorld and Lab2 should share some code, you may extract it to a separate file, e.g. common.c, then update the project to say
add_executable(hello_world HelloWorld.c common.c)
add_executable(MeusCodigosC_2_0 AtividadeProducaoLabU2.c common.c)
I had this problem in clion and i fixed that. I Just opened new project and ta damm it worked.
it seems so easy to fix but my first time to using this so it was hard little bit for me :)
Related
I download iasl 20190509 version in Ubunt18.04.5 LTS.
When I use "make iasl" command to build the package, I get this error:
$ make iasl
make[1]: Entering directory 'acpica-unix2-20190509/generate/unix/iasl'
- bison obj/aslcompiler.y
acpica-unix2-20190509/generate/unix/iasl/obj/aslcompiler.y:1.1: error: syntax error, unexpected end of file
mv: cannot stat 'obj/AslCompiler.LLW4kB/y.tab.h': No such file or directory
Makefile:322: recipe for target 'obj/aslcompiler.y.h' failed
make[1]: *** [obj/aslcompiler.y.h] Error 1
make[1]: Leaving directory 'acpica-unix2-20190509/generate/unix/iasl'
generate/unix/Makefile.common:7: recipe for target 'iasl' failed
make: *** [iasl] Error 2
Please help me fix this error.
Please help me build iasl.
The solution was to retry the make but making sure that the build directory is clean first:
$ make clean && make
Here's my best guess as to what happened:
An attempt was made to build the software package.
That attempt failed because the m4 tool had not previously been installed.
OP installed m4, and reran the build with make.
Because of an inadequacy in the provided Makefile, make did not attempt to run m4 again. (See below.) Consequently, processing of the file supposedly generated by m4 failed.
This software package relies on m4 to create the source for bison by interpolating various component files. (Yacc/Bison doesn't have an include feature, so m4 is the usual solution.) However, the command to run m4 is roughly (with paths simplified):
$ m4 aslparser.y > aslcompiler.y
When the shell executes this command, it creates or truncates aslcompiler.y
before even attempting to invoke m4. If it turns out that m4 can't be found, or if m4 produces some sort of error, you end up with an empty or partial output file.
The make target aslcompiler.y is satisfied by this artefact, since make only cares that the target was created later than its dependencies. So the next invocation of make goes on to the next step (bison aslcompiler.y), which fails because aslcompiler.y is empty.
The Makefile would have been better written to use a command like:
$ m4 aslparser.y > /tmp/aslcompiler.y && mv /tmp/aslcompiler.y aslcompiler.y
in order to avoid creating the target if m4 failed. Of course, that's not your responsibility. It could be reported as a bug to the iASL project. (The Makefile already uses this strategy to safely handle the files generated by Bison, so it's not really anything new.)
I'm fairly new to programming in AS7, I've only programmed a few things in assembler but wanted to see if the mplab snap could program the MCU in C, but I just haven't found a way around it (this pops up when I start debbuging). Whenever I try to build an error "recipe for target '...' failed" shows up, be it in an XC8 or a GCC project.
#include <avr/io.h>
int main(void)
{
/* Replace with your application code */
while (1)
{
}
}
Even if the code does absolutely nothing, so I take it it's not because of the code, I suppose.
------ Build started: Project: GccApplication3, Configuration: Debug AVR ------
Build started.
Project "GccApplication3.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in the file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from the project "C:\Users\Julio\Documents\Atmel Studio\7.0\GccApplication3\GccApplication3\GccApplication3.cproj" (target "Build" depends on it):
Using "RunCompilerTask" task from assembly "C:\Program Files (x86)\Atmel\Studio\7.0\Extensions\Application\AvrGCC.dll".
Task "RunCompilerTask"
Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils
C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 4 --output-sync
C:\Users\Julio\Documents\Atmel Studio\7.0\GccApplication3\GccApplication3\Debug\Makefile(106,1): error: recipe for target 'GccApplication3.elf' failed
make: *** [GccApplication3.elf] Error 1
Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "GccApplication3.cproj" -- FAILED.
Done building project "GccApplication3.cproj" -- FAILED.
Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
that's the output I usually get from it, and the line of the makefile which it makes reference to (106,1) is
#echo Building target: $#
that I personally don't know what it means or if it should allude to that line in general.
I've attempted to fix it by making a clean reinstall and tried a couple of older versions to see if it might work but it always comes down to the same error. The only files that are inside the Debug folder are the 'main.d' 'main.o' 'makedep.mk' and the 'makefile'. I probably didn't set something that was important right from the beginning so if anybody knows something I'd be pleased.
(I don't even know how to read a makefile yet so there's that)
I am fairly new to programming and have mostly programmed using textfiles but now I am supposed to start using CodeLite for an assignment. I am using windows 10 64-bit.
The problem is that I cannot seem to get my compiler to work in codelite the error message I receive is this:
C:\WINDOWS\system32\cmd.exe /C C:/TDM-GCC-32/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile
"----------Building project:[ hello - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/codelitews/hello'
'makedir' is not recognized as an internal or external command, operable program or batch file.
mingw32-make.exe[1]: *** [Debug/.d] Error 1
mingw32-make.exe[1]: *** Waiting for unfinished jobs....
hello.mk:88: recipe for target 'Debug/.d' failed
built-in: fatal error: opening dependency file ./Debug/main.c.o.d: No such file or directory
compilation terminated.
mingw32-make.exe[1]: *** [Debug/main.c.o.d] Error 1
hello.mk:99: recipe for target 'Debug/main.c.o.d' failed
mingw32-make.exe[1]: Leaving directory 'C:/codelitews/hello'
mingw32-make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
====1 errors, 0 warnings====
And I cannot figure out what this means and why it happens since the same compiler works just fine with codeblocks. I have tried googling this issue but have not found something useful. Help would be much appreciated.
Thanks.
CodeLite should be able to recognize makedir.exe it is located under the same folder where you installed codelite.exe
If it does not, then it means that something terribly went wrong, usually this happens when you start modifying the PATH environment variable without knowing what you are doing.
Can you please paste the content of your environment variable (from within CodeLite). From the main menu, go to: Settings->Environment Variables and paste here the content of the text box
Eran
I am trying to cross compile a simple program with the arm toolchain. And stdio library points to another library, which results in the following error:
/home/sansari/tools/arm-eabi-4.7/bin/arm-eabi-gcc hello.c -o hello
In file included from hello.c:3:0:
/home/sansari/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/include-fixed/stdio.h:50:23: fatal error: sys/cdefs.h: No such file or directory
compilation terminated.
make: *** [hello] Error 1
At first, I thought this file is in some subdirectory of the toolchain, and I need to include the folder for this library in my makefile. But a quick tree output says that it is not. So given that I have used this toolchain successfully for a larger project, I know it is copied from somewhere. So my question is how do I add it to this project please? And what is the appropriate place to copy it from? I am trying to understand why it is not in the toolchain folders that I have, and how I should add it to my project please.
#Olaf - You have been very helpful; I however have a little more learning curve. But I do understand what you are instructing. I know I have the libraries in my build system since have built for this platform successfully. I even know that it is in my WORKING_DIRECTORY. What I do not know is if I can copy a folder and address the issue entirely or do I need to keep compiling and see what errors I get. That is do it incrementally. For example, one of the files, which was missing was cdefs.h. And I was able to find it in the folder:
/home/sansari/ndk/android-ndk-r10d/platforms/android-19/arch-arm/usr/include/sys/cdefs_elf.h
So I copied it over and the build process proceeded to the next stage. I do like to know if I should perhaps have copied the entire /sys or /include directory or compared the /include directory of my source and make sure all the files are also in the destination directory also. And that way I can avoid having to compile a number of times.
But nevertheless, I proceeded with copying one file at a time. The last error I got is:
/home/sansari/tbt/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/include/stdint.h:3:26: fatal error: stdint.h: No such file or directory
And I look in the include directory; I see a file call stdint.h
What do you make of that? Does that make sense to you? I am confused by this error. How can I get this error when the file is in the directory. Basically it seems make is saying this file does not exist when it does.
I did find This post also, which seems to say what you are saying. I just need to know what is the best way to address it.
#Olaf - I really appreciate all your help. I was able to get through all the library errors by putting an include statement in my makefile. Now the linker is giving me errors as follows:
/home/sansari/tbt/tools/arm-eabi-4.7/bin/arm-eabi-gcc -I../../ndk/android-ndk-r10d/platforms/android-19/arch-arm/usr/include hello.c -o hello
/home/sansari/tbt/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/../../../../arm-eabi/bin/ld: cannot find crt0.o: No such file or directory
/home/sansari/tbt/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/../../../../arm-eabi/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
make: *** [hello] Error 1
update - I searched for a solution for the above errors. The first error is discussed here and -nostartfiles switch seems to work for me for now. I found this link that talks about libc.a being the fix for the error about not finding -lc. So I found an appropriate copy of libc.a and passed the location to the linker. The program compiles, but I get one last warning as follows:
warning: cannot find entry symbol _start; defaulting to 00000000000080dc
For which this link suggested using --entery-main switch. So now I have an executable. I want to thank you again. If you do see any problem in what I have done, please post something for me. it is gonna take a while for me to get this executable on my device.
Since I am just now learning C I want to be able to create one "Projects" folder in XCode to hold all my mini files that I create to learn different stuff. Such as HelloWorld.c IfElse.c WhleLoop.c however I am having a major issue. I can't run these different main files without getting the error below...
duplicate symbol _main error:
linker command failed with exit code 1 (use -v to see invocation)
What is the easiest way to go about this? I want to only have one project open in Xcode to be able to very easily reference my previous files and just create little tests files that do different learning things before I really get into C.
Can anyone suggest a workaround?
-Henry
The best is to write Makefile
Open one new file with the name "Makefile"
In that file type as given below:
all:hello ifelse while
hello:HelloWorld.o
<tab>cc -o hello HelloWorld.o
ifelse:IfElse.o
<tab>cc -o ifelse IfElse.o
WhileLoop.o:WhileLoop.o
<tab>cc -o while WhileLoop.o
The above given is a makefile which are used for creating multiple executables under a single project in Linux. It is also available in standard sdks like Eclipse. For any new file you want compile add it to the makefile as shown for other files.
Once you finish writing the makefile enter the command make in the terminal.
Everything will get compiled and different executables get created.
To know more about the makefile you can refer to the below link:
http://www.cs.wmich.edu/~sdflemin/instr_pgs/make/index.html