I am trying to build and run a basic C program in Xcode, but keep getting a "build failed" message. The script is nothing too crazy, just a natural number calculator, there's nothing wrong with the script as I've tested it on an online compiler and it works fine.
This is the full error message:
Ld /Users/Matt/Library/Developer/Xcode/DerivedData/testing.c-ckojksceiqxrcdcfavsxvsgvapin
/Build/Products/Debug/testing.c normal x86_64
cd /Users/Matt/Code/testing.c
export MACOSX_DEPLOYMENT_TARGET=10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform
/Developer/SDKs/MacOSX10.9.sdk -L/Users/Matt/Library/Developer/Xcode/DerivedData/testing.c-
ckojksceiqxrcdcfavsxvsgvapin/Build/Products/Debug -F/Users/Matt/Library/Developer/Xcode/DerivedData
/testing.c-ckojksceiqxrcdcfavsxvsgvapin/Build/Products/Debug -filelist /Users/Matt/Library/Developer
/Xcode/DerivedData/testing.c-ckojksceiqxrcdcfavsxvsgvapin/Build/Intermediates/testing.c.build/Debug
/testing.c.build/Objects-normal/x86_64/testing.c.LinkFileList -mmacosx-version-min=10.9 -Xlinker
-dependency_info -Xlinker /Users/Matt/Library/Developer/Xcode/DerivedData/testing.c-
ckojksceiqxrcdcfavsxvsgvapin/Build/Intermediates/testing.c.build/Debug/testing.c.build/Objects-
normal/x86_64/testing.c_dependency_info.dat -o /Users/Matt/Library/Developer/Xcode/DerivedData
/testing.c-ckojksceiqxrcdcfavsxvsgvapin/Build/Products/Debug/testing.c
duplicate symbol _main in:
/Users/Matt/Library/Developer/Xcode/DerivedData/testing.c-ckojksceiqxrcdcfavsxvsgvapin/Build
/Intermediates/testing.c.build/Debug/testing.c.build/Objects-normal/x86_64/tests.o
/Users/Matt/Library/Developer/Xcode/DerivedData/testing.c-ckojksceiqxrcdcfavsxvsgvapin/Build
/Intermediates/testing.c.build/Debug/testing.c.build/Objects-normal/x86_64/main.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Anybody know how to solve this? I've been searching for an answer for ages with no luck.
You have two "main" functions defined.
One in a file named "main.c" and the other in a "tests.c" file. Remove one of them and you should be okay!
Or, if you only have a "testing.c" file, do a Clean on your xcode project and try building again.
Related
I am attempting to compile a C program on macOS Catalina. The program will make use of bzip2 decompression. My code includes the line
#include <bzlib.h>
and I am trying to call the function BZ2_bzBuffToBuffDecompress. However, when I run gcc myfile.c -o myfile.c.o, I get the following error:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
I am just using a plain text editor and gcc, no IDEs and no CMake files. I suspect I may need a CMake file for this but I am not really sure how to proceed. Any assistance with this is greatly appreciated!
You need to link in the bzip library. gcc myfile.c -o myfile -lbz2. That command assumes the lib is installed into the standard location. Also, you are compiling a final executable so (by strong convention) it should not have a .o suffix.
I am having an issue trying to compile my C program. I'm on macOS Catalina and using clang to compile.
When I try to SDL_Init( SDL_INIT_VIDEO ); and compile clang tells me there is a linker command failure
Undefined symbols for architecture x86_64:
"_SDL_Init", referenced from:
_main in main-1defaf.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I used brew to install SDL2 with brew install SDL2. So these are flags I have tried to have clang pass to the linker but neither one worked.
> clang main.c -L/usr/local/Cellar/sdl2/2.0.12_1/include/SDL2
> clang main.c -L/usr/local/Cellar/sdl2/2.0.12_1/include/SDL2 \
-L/usr/local/Cellar/sdl2/2.0.12_1/lib
Since they did not work I then tried to add the -framework flag. I followed the instructions I found here to install the framework. However the website didn't mention how to use it with clang. Clangs documentation did not mention if I needed to point to the framework file or directory so I tried a couple different ways but could not get any to work.
> clang main.c -L/usr/local/Cellar/sdl2/2.0.12_1/include/SDL2 \
-framework SDL2
ld: framework not found SDL2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
> clang main.c -L/usr/local/Cellar/sdl2/2.0.12_1/include/SDL2 \
-framework /Library/Framework/SDL2.framework
ld: framework not found /Library/Framework/SDL2.framework
clang: error: linker command failed with exit code 1 (use -v to see invocation)
> clang main.c -L/usr/local/Cellar/sdl2/2.0.12_1/include/SDL2 \
-framework /Library/Frameworks/SDL2.framework/SDL2
ld: framework not found /Library/Frameworks/SDL2.framework/SDL2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have also tried to just use XCode to compile and it builds successfully however fails to run with the error below. I followed the instructions in the tutorial linked above.
2020-06-30 16:07:36.220432-0700 sdl_test[1867:31873] Metal API Validation Enabled
2020-06-30 16:07:36.273590-0700 sdl_test[1867:32300] flock failed to lock maps file: errno = 35
2020-06-30 16:07:36.274022-0700 sdl_test[1867:32300] flock failed to lock maps file: errno = 35
Program ended with exit code: 0
I have restarted the computer and cleaned the build and based on some google searches it seems like this was introduced in a recent version of XCode that needs to be resolved.
I would like to stick with clang and not sure what else I can try to get this to compile. I would like to get some direction on next steps.
This is the code I am trying to run.
#include <SDL2/SDL.h>
#include <stdio.h>
int main(int argc, const char * argv[]) {
SDL_Init( SDL_INIT_VIDEO );
return 0;
}
You're missing the -lSDL2 to bring in the shared library, and if you're going to use /usr/local/Cellar/sdl2/2.0.12_1/include/SDL2 you should only #include <SDL.h>.
Consider using pkg-config to handle include and link flags.
clang main.c -o main `pkg-config --libs --cflags sdl2`
I have a header file included in the main but when I compile the main, I have an error saying that the linker failed.
I tried to find the object files but I cannot find them.
I think the problem may come from my machine. I am kind of a beginner so I don't know how to solve this
When I try compiling my code I get this error:
Undefined symbols for architecture x86_64:
"_intClassic", referenced from:
_main in main-53b7e4.o
"_intQuadrature", referenced from:
_main in main-53b7e4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#zwol #JonathanLeffer I have 3 files in my project main.c, integral.h
and integral.c. integral.c contains the code of the functions
intClassic and intQuadrature that allow me to calculate different
types of integral. In integral.h I declared the functions and
structures I use. Finally in the main I included integral.h .
Also $ gcc -o output file1.o file2.o can this command help me ?
In the same directory as your files, try running the command
gcc main.c integral.c -o integral
This should take the 2 files and compile them into a program called ./integral
I just started to learn gcc/g++ by reading "An introduction to GCC"
In chapter 3.1 the author showed an example of linking with external libraries and header files. The main source code uses 'gdbm.h' header (installed at /opt/gdbm-1.8.3/include/ in text book) file and the library ‘libgdbm.a’ (installed at /opt/gdbm-1.8.3/lib/ in text book). The process of linking with the library and header file is as follows:
Link to example screenshot
When I tried to repeat this, I got a contradictory result. When I used method 1 (in the example fails) which only includes header file path, the program can be compiled, however, when I used method 2 (in the example succeeds), I got an error, saying that
"ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1"
(this is my full command line and error message:)
userMacBook-Pro:03 user$gcc -Wall -I/usr/local/include dbmain.c -L/usr/local/lib dbmain.c -lgdbm
duplicate symbol _main in:
/var/folders/6_/09vfzzms7dq1d73vl4mwlxmh0000gn/T/dbmain-9d15f9.o
/var/folders/6_/09vfzzms7dq1d73vl4mwlxmh0000gn/T/dbmain-907e96.o
this is my command that succeeds:
userMacBook-Pro:03 user$ gcc -Wall -I/usr/local/include dbmain.c -lgdbm
userMacBook-Pro:03 user$ ./a.out
Storing key-value pair... done.
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can anyone explain why this happens?
I don't know which platform the author uses, I just use mac OS X.
gcc -Wall -I/usr/local/include dbmain.c -L/usr/local/lib dbmain.c -lgdbm
The file dbmain.c is present twice on your command line. For this reason the main function is present twice.
I try to add gsoap in my application.
I built gsoap for i386.
Created c code with under commands:
wsdl2h -c -s -o soap.h soap.wsdl
soapcpp2 -c -C soap.h
I got files. After this I tried to include these to my app.
I added to my project in xCode. Also I added 6 libraries(libgsoap.a,libgsoap++.a,libgsoapck.a, libgsoapck++.a, libgsoapssl.a, libgsoapssl++.a). I added libraries in Target => Build phases => Link binary with libraries.
But I got error....
ld: duplicate symbol .....
I thought it happened cause in file soapClientLib.c was it:
#ifndef WITH_NOGLOBAL
#define WITH_NOGLOBAL
#endif
#define SOAP_FMAC3 static
#include "soapC.c"
#include "soapClient.c"
Comments for these was:
Use this file in your project build instead of the two files soapC.c and soapClient.c. This hides the serializer functions and avoids linking problems when linking multiple clients and servers
I removed it content.
But after this I got next error...
Undefined symbols for architecture i386:
"_namespaces", referenced from:
_soap_init_LIBRARY_VERSION_REQUIRED_20812 in libgsoap.a(libgsoap_a-stdsoap2.o)
(maybe you meant: _soap_set_namespaces, _soap_set_local_namespaces )
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And Now I have no idea...
I used gsoap in windows and I added it to my project for 5 minutes. But I wasted much time to add it in mac os.
Can you help me?
I resolved my problem!
I had to do ./configure with keys --disable-namespaces.
Thank you.
But I steal don't understand sense of the file soapClientLib.c.
I know, that this is an old question, but I've just spent an entire evening figuring this out.
Here is a quote from this conversation (another link):
The soapcpp2-generated xyz.nsmap file should be #include'd in your code. It
contains a global XML namespace mapping (or binding) table.
The reason for including this separately is that there are scenarios where the
namespace mapping table is customized or shared.
For instance, I used a C++ classes, generated with soapcpp2 -i <my_header.h>. One of generated files is a <my_service_name>Service.cpp. To get rid of the _namespaces issue I had to #include "<my_service_name>.nsmap" in it.
As for the soapClientLib.c, I's like to quote that conversation again:
Please do not use soapClientLib.c in your build unless you want to combine
multiple separately-generated clients/server codes. This means that the
soapClientLib.c do not include the shared serializers for SOAP headers and
faults.
This problem can be solved with changing compiler filename from gcc to g++.
GCC:
gcc calcmain.cpp soapC.cpp soapcalcProxy.cpp -I/opt/local/include -lgsoap++ -L/opt/local/lib
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
G++:
g++ calcmain.cpp soapC.cpp soapcalcProxy.cpp -I/opt/local/include -lgsoap++ -L/opt/local/lib
All OK
Yet you can make it compilable under gcc, with adding an gcc option -lstdc++:
gcc calcmain.cpp soapC.cpp soapcalcProxy.cpp -I/opt/local/include -lgsoap++ -L/opt/local/lib -lstdc++
All OK