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
Related
I am currently working on a project in C. I searched through multiple similar questions, but the answers are too unspecific for me, because I haven't really worked with C in the past.
My problem is the following:
The project consists of multiple different files. I am editing the file "pm3/armsrc/epa.c". Now i need to use a function from another file. This function is located in "pm3/common/mbedtls/sha1.c.
I tried to include this file in my epa.c like this:
#include "../common/mbedtls/sha1.h"
It seems to work and I could access the function. But after starting the Makefile in order to compile the project (which worked fine until now), i get an error message in epa.c:
undefined reference to `mbedtls_sha1_ret'
In other answers it seems to be a problem with the linker and the gcc call, but the Makefile, which calls multiple other Makefiles in order to build everything are all pre-made. As you can see here in the "make all" output, the file with the needed function is successfully builded:
Compiling mbedtls
cd ../common/mbedtls && make all
make[2]: Entering directory '/pm3/common/mbedtls'
ar rcs libmbedtls.a aes.o asn1parse.o asn1write.o base64.o bignum.o ctr_drbg.o entropy_poll.o entropy.o error.o timing.o ecp.o ecp_curves.o certs.o camellia.o blowfish.o cipher_wrap.o cipher.o cmac.o des.o ecdsa.o md.o md_wrap.o md5.o oid.o pem.o arc4.o pk.o pk_wrap.o pkwrite.o pkcs5.o pkcs12.o pkparse.o platform.o platform_util.o rsa.o rsa_internal.o sha1.o sha256.o sha512.o threading.o x509.o x509_crl.o x509_crt.o
ranlib libmbedtls.a
make[2]: Leaving directory '/pm3/common/mbedtls'
If someone could maybe take a look at the Makefiles or if someone has another possibility in order to get the compilation working, I would be very happy. Here is the link to the git-repo: https://github.com/Proxmark/proxmark3. My knowledge of Makefiles is very low, so I don't see any problems in the pre-made ones.
Without diving into the makefile, you did use the include directive correctly,
but probably the executable's make command (link) did not include the
library you now used (and refernced).
Look for the place in the makefile where there is a call to the linker
(gcc or maybe g++ or ld), and see if the library (probably mbedtls) appears on the
list of files being linked.
I once tried to compile a C program I made that was for a chess game (thanks to YouTube's Bluefever Software for the tutorial), but when I went to compile the program, I executed this line of code:
C:\TDM-GCC-64\>gcc Chess/chess.c Chess/init.c -o chess
The compiling worked (there were no syntax errors or anything), but when I got to my file directory, I saw this (circled in blue):
An unexpected application (but there were no viruses!):
How did this happen? It may had something to do with the line I was compiling, but what is the "intel" behind this?
It is normal for the compiler to generate an application!
What is surprising is the location for the executable, it should have been generated in the parent directory:
C:\TDM-GCC-64\> gcc Chess/chess.c Chess/init.c -o chess
The explanation is interesting:
You are using the Windows operating system, where the filenames are case insensitive.
You instructed gcc to generate the executable into chess, but this is the name of the Chess directory. In this case, gcc generates the executable in the named directory and gives it a name that is the basename of the first source file chess.c -> chess.
Furthermore, the application name really is chess.exe in Windows, but the default setting for the file manager is to not display file extensions. This is a very unfortunate choice. I suggest you change this setting in the Windows/File Explorer Options window to always show file extensions. This will allow you to distinguish chess.c, chess.exe and chess.h more easily.
You have a Makefile in the Chess directory, you should use the make command to build the executable:
C:\TDM-GCC-64\> make -C Chess
Or simply cd to the Chess subdirectory and type:
C:\TDM-GCC-64\Chess> make
That's the file you told the compiler to make.
The -o option to gcc is the output file. In this case, you told it to create an executable file named chess. And that's exactly what was created.
The compiler is automatically creating an executable file while compiling.
I am trying to test the VHDL AVR8 soft processor found on Gadget Factory on a Digilent Nexys II (Spartan 3E) Development board. The project includes a Makefile for compiling a C (or other) software program and merging it with the FPGA bitstream so there is no need to resynthesize the HDL with every iteration of the software.
When I execute 'make' I get the following error associated with data2mem:
Merging Verilog Mem file with Xilinx bitstream: main.bit
data2mem -bm bin/top_avr_core_v8_bd.bmm -bt bin/top_avr_core_v8.bit -bd main.mem -o b main.bit
process_begin: CreateProcess(NULL, data2mem -bm bin/top_avr_core_v8_bd.bmm -bt bin/top_avr_core_v8.bit -bd main.mem -o b main.bit, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [main.bit] Error 2
I am executing 'make' in the same directory containing the VHDL project files, and I even have a blank 'main.bit' file in the directory.
Does anyone have any ideas about what's going on here? Does my blank 'main.bit' file need to be formatted a certain way or placed in a different location?
The following is a link to my Makefile:
Makefile
Other information to note: I'm new to using Makefiles in general, let alone for the specific purpose of merging software with an FPGA bitstream file. Also, I am attempting this on a Windows 7 machine in command prompt.
Thanks in advance.
Edit: Here's a link to the AVR8 soft processor on Gadget Factory, and here's the AVR8 source.
Offhand I'd say make cannot invoke the data2mem program. Do you have such a program on your system? Is the directory containing it in your PATH variable? Does it run properly? For example, can you type in that command line yourself at the command prompt and have it work properly?
When you say a "blank" main.bit, I assume you mean a "fully populated except for the memory that I want to put the program into" main.bit... otherwise nothings going to work!
It sounds like you do not have data2mem on your path - are you sure you are running your makefile from a command window/shell which includes the xilinx paths?
On Windows, there is a specific icon for this. Alternatively you can open any old command prompt and run the settings32.bat (or settings64.bat) file from within the Xilinx install folder to get set up. Or on linux, you can source the appropriate .sh/.csh file in your shell.
I am on RHEL 6.0 and got hold of the source code for join command(hopefully from the right source!!). I rarely work on a C code and hence finding this difficult. I am trying to compile and run the C code for join, but running into compile time errors.
g++ join.c
join.c:19:20: error: config.h: No such file or directory
join.c:25:20: error: system.h: No such file or directory
join.c:27:25: error: hard-locale.h: No such file or directory
join.c:28:24: error: linebuffer.h: No such file or directory
join.c:29:24: error: memcasecmp.h: No such file or directory
join.c:30:19: error: quote.h: No such file or directory
join.c:31:21: error: stdio--.h: No such file or directory
join.c:32:22: error: xmemcoll.h: No such file or directory
join.c:33:21: error: xstrtol.h: No such file or directory
join.c:34:22: error: argmatch.h: No such file or directory
Since I am not aware of where to find these libraries(I did google for each one and they are spread all over different websites), can anyone please guide me as to how I can link these libraries together and compile the source code of join command?
This is not a linking problem as you suggest. Instead, you get these errors because g++ can't find these files: config.h, system.h, ..., that are #included (indirectly) by join.c.
What you could do is find these files on your system, and then add as many -I<directory> options behind the g++ as there were directories you found these files in. Do man g++ for more info.
You'll also need to find the where the libraries are you need to link against. So you'll need to specify more than -I's.
On the other hand, aren't there 'configure' or other package files? Normally you don't have to specify compiler flags (like this -I) by hand. Instead, it's common that for example Makefile's are generated from such a configuration file, after which you just have to type make.
I advise you to get someone that has done this before, because you don't seem to understand the basics of C program compilation. This can cost you a lot of your precious time without results. But good luck anyway!
Perhaps you don't have everything in place to compile your code. Try installing the build-essential package.
sudo yum install build-essential
On a relevant note, I'm not aware of the script join.c but if you are looking for a way to concatenate a bunch of files together, you can do cat FILE1 FILE2 FILE3 > BIG_FILE where FILE1 FILE2 FILE3 are the files you want to join them. Under RHEL 6.0, you can use asterisks too, if there is a pattern. For example, cat FILE.00* > BIG_FILE
I'm trying to accelerate a key function in a c project (not c++) using CUDA.
For some reason, i can't get the Makefile's to recognise the .cu extension when I change the name of one of the files to .cu.
It's using a configure script and .am/.in/.deps files, which I don't really understand all that well, but basically I grepped references to file.c and changed them all to file.cu, but it produces a file.o: File Not Found error.
Top level make file
https://www.dropbox.com/s/g282qvbdu8pdas0/Makefile
Src folder makefile
https://www.dropbox.com/s/b4pq026od8gauqi/Makefile
The search command I used was
grep -R -i "file.c"
and I simply changed them all to file.cu, then re-ran configure, make clean, make all - result is File Not Found.
I suppose it must be something to do with extensions being ignored/accepted by the Makefile, but as it's been a long time since I've programmed in C and I've never used such complex Makefiles I don't know how to fix it.
Any ideas?
*PS Also, file.cu has compile errors at the moment, but the error message I'm getting is File Not Found, so I think that's not the problem.
You need to have a rule to build o file from a cu file:
cudafile.o: cudafile.cu
nvcc $(NVCC_FLAGS) -c %< -o $#
So you also need to specify the rule for the cu file, and use nvcc for compilation.
The following guide seems to cover it...
http://mcclanahoochie.com/blog/2011/02/automake-and-cuda/
Actually, most of the advice given in the link seems unnecessary for basic compilation, but for some reason I found that when I re-created the config file using autoconf it worked. No explanation comes to mind.