I am trying to use SDL in Xcode. I included the necessary header files. However, I keep getting error messages at compilation that look like this: Undefined symbol: _AudioObjectAddPropertyListener. I keep getting 100 of these error messages. My code to test SDL looks like this: if (SDL_Init(SDL_INIT_VIDEO)) {cout << "SDL init failed \n";return 1;} else {cout << "SDL Init succeeded \n";SDL_Quit();return 0;}
I'm not sure if I included the libraries in the correct way. I tried googling "undefined symbol error Xcode SDL" and none of the results helped me solve my problem.
I have a screenshot of the error messages below.
Asked
Active
Viewed 127 times
1

Daniel Eremin
- 9
- 4
-
You need not only to include header files but also to link library in the command line. E.g. for GCC linking sdl library looks like this in command line `g++ main.cpp -lSDL2` where `main.cpp` is your source file. There should be some project settings in XCode to add extra linking of libraries, so that you don't need to modify command line. E.g. [in this answer](https://stackoverflow.com/questions/445815/linking-libraries-in-xcode) is told about how to link extra libraries. – Arty Dec 27 '20 at 04:34
-
@Arty If I try to include the library using the method described in the answers of the question you linked I now get one error: **Library not found for -libSDL2** – Daniel Eremin Dec 28 '20 at 21:22
-
That error happens because when you link something in Unix-like systems then you have to remove "lib" prefix from name, e.g. if you want to link sdl library then you write `-lSDL2`. In general if library is named lib**Something** then you have to write option `-lSomething`, i.e. without `lib` prefix. Also notice presence of `l` letter after `-`, this letter means `link`, i.e. `-lSomething` means `"link library Something"`. In other words you have to write `-lSDL2`. – Arty Dec 29 '20 at 04:22
1 Answers
0
Steps:
- Open project configuration
- Go to build settings tab
- Add library search paths
- In other linker flags add
-L/usr/local/lib -lSDL2 -lm
- Try to compile again

Daniel Eremin
- 9
- 4