I am developing for OSX 10.8. I just installed libpcap via MacPorts and tried running a simple device hunter (below)
#include <stdio.h>
#include <pcap.h>
int main(int argc,char *argv[])
{
char *dev, errbuf[PCAP_ERRBUF_SIZE];
dev = pcap_lookupdev(errbuf);
if(dev == NULL)
{
fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
return(2);
}
printf("Device %s\n", dev);
return(0);
}
and while trying to compile with g++ i am getting:
Undefined symbols for architecture x86_64:
"_pcap_lookupdev", referenced from:
_main in ccIMp1m2.o
Any helpful advice so I can actually get started with learning this stuff would be great! I googled for a solid 10-15 minutes but just couldn't find much on my particular issue with my setup.
You need to link libpcap. Probably -lpcap added to your compiler command line will work. If it's installed somewhere strange (and it might be, since you got it from MacPorts), you might need -L/path/to/libpcap -lpcap.
Related
I've got some problems getting up Allegro 5 library in Visual Studio 2017. In most cases i'm getting linker errors (unknown/unrecognized external types).
I said in most cases, because this code:
#include <stdio.h>
#include <allegro5/allegro.h>
int main(int argc, char **argv) {
ALLEGRO_DISPLAY *display = NULL;
if (!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
display = al_create_display(640, 480);
if (!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
al_clear_to_color(al_map_rgb(0, 0, 0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
return 0;
}
source:https://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Displays
compiles as usual without errors and runs as expected.
But this code:
#include "allegro5/allegro.h"
#include "allegro5/allegro_image.h"
#include "allegro5/allegro_primitives.h"
int main(int argc, char **argv){
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_DISPLAY_MODE disp_data;
al_init(); // I'm not checking the return value for simplicity.
al_init_image_addon();
al_init_primitives_addon();
al_get_display_mode(al_get_num_display_modes() - 1, &disp_data);
al_set_new_display_flags(ALLEGRO_FULLSCREEN);
display = al_create_display(disp_data.width, disp_data.height);
al_rest(3);
al_destroy_display(display);
return 0;
}
source: the same, next tutorial.
gets me 3 errors in linker. Many other codes do as well with various numbers of errors in linker.
In this prticular case are the errors as folows:
Error code Description
LNK2019 Unrecognized external symbol __imp__al_init_image_addon reffered in function _main
LNK2019 Unrecognized external symbol __imp__al_init_primitives_addon reffered in function _main
LNK1120 Number of unrecognized external types:2
I've read that Allegro has some dependencies in freetype, so i installed it using NuGet(project pakage manager), the same way as Allegro.
I'm new to Visual Studio, so if you have a possible solution, please explain step by step (and, if you are capable of it, please explain, so I can learn something new)
If you need something to find the solution, just ask and explain how can i get it.
Thanks a lot in advance.
Yep, I'm just stupid.
I'm sorry for all the trouble I've caused.
It was because I didn't know that I have to enable the modules in project properties under Allegro 5 tab. Now I've got it up and running.
I'm very sorry for bothering you.
Glad you solved it. For the record, the addon libraries are not linked by default in the Nuget Package for VS. After installing the Allegro 5 Nuget package for your solution, right click on the project properties and select Allegro5 from the menu on the left. Go to addon libraries, and enable the addons you're using. Easy peasy.
I thought Ubuntu and OS X would have similar interfaces for compiling a C/C++ program with SDL but nothing I am trying, or finding on Google seems to be working.
I have found a solution for Xcode, but I am not using Xcode. I am writing my programs from Sublime Text 2 and compiling via command-line since I prefer it and work much faster that way.
Long story short, I am receiving an array of errors with each attempt and thus far I have copied SDL.framework into my /Library/Frameworks directory.
This is the closest I have gotten to actually compiling:
[ 674 / 174 / 0 ] $ compcpsdl
Undefined symbols for architecture x86_64:
"_SDL_main", referenced from:
-[SDLMain applicationDidFinishLaunching:] in ccYYA0Ea.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Terminal command (i.e. compcpsdl)
g++ -I/Library/Frameworks/SDL.framework/Headers main.cpp SDLmain.m -framework SDL -framework Cocoa
With the following project structure:
Project-Directory/
--- main.cpp
--- SDLMain.m
--- SDLMain.h
And lastly, the following source code:
#include <iostream>
#include <SDL/SDL.h>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
It appears I'm doing everything correctly, yet nothing seems to be working.
Any ideas guys?
I Think SDL does sometimes a bit strange stuff with the main function it assumes the mainfunction is defined in one way. Notice that I added int argc and char** argv to the definition of you main function.
Try:
int main (int argc, char** argv)
{
cout << "Hello World!";
return 0;
}
I encountered this problem also once and it was quite mystifying.
for more info see this stackoverflow question: Why SDL defines main macro?
I am using C++ with the SDL Cocoa and Foundation framework on my mac os x. I get the following error
Undefined symbols for architecture x86_64:
"_SDL_main", referenced from:
-[SDLMain applicationDidFinishLaunching:] in SDLMain.o
ld: symbol(s) not found for architecture x86_64
when I run the following code
#import <Foundation/Foundation.h>
#import <SDL/SDL.h>
#include "SDLMain.h"
int main(int argc, const char * argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode(640,480,32,SDL_DOUBLEBUF);
SDL_Event event;
bool isRunning = true;
while(SDL_PollEvent(&event)){
if(event.type == SDL_QUIT){
isRunning=false;
}
}
SDL_Quit();
return 0;
}
I have no idea what is wrong, although it seems that when I go into the SDLMain.m file and comment out this line of code
status = SDL_main (gArgc, gArgv);
the program compiles with no problems. However, it doesn't work. No window opens like its supposed to. Any ideas?
I bet your main function signature is incorrect. You use:
int main(int argc, const char * argv[])
^^^^^
but SDL_main.h wants
int main(int argc, char *argv[])
Why?
You see, SDL does something really horrific when compiling: It renames your main function to SDL_main, injecting its own main function which, in turn, calls yours.
Note that if this doesn't work, then you may be compiling with wrong flags. To be sure, get the flags by typing:
$ sdl-config --cflags --libs
For more information, see Simply including SDL header causes linker error
I had the same problem, even though my main signature was correct. I Found the answer here: SDL in XCode 4.3.2 SDLMain.o undefined symbols
Turned out the problem was that I added SDLMain.m and SDLMain.h
(according to a suggestion on the libSDL website about OS X
frameworks) to an existing SDL project which messed up with main.
Bottom line is that you don't need those files just because you are
using Cocoa -- SDL's own test apps don't use it either and run just
fine on OS X.
I am having trouble using the SDL framework in my xcode project, my main (all there is in the project at the moment) currently looks like this:
#include <SDL/SDL.h>
#include <iostream>
int main(int argc, const char * argv[])
{
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
And the error I am receiving when building is:
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
(maybe you meant: __Z8SDL_mainiPPKc)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It does not give me an error about the framework not being found. and I have looked around Stackoverflow for this problem and I did find one person who had their framework in the wrong place on their OS. But I have tried all places (/library/frameworks && /~username~/library/frameworks && /system/library/frameworks) and still no luck.
Additional info:
I did however notice after some searching on the internet that the official website http://www.libsdl.org/download-1.2.php
Does not have a OSX version of the Development library. While many tutorials on how to use SDL on OSX say these are required.
Also I am adding my library via Xcode itself ,not through drag'ndrop. Xcode seems to reckognize it.
Would be much appreciated if anyone could help, going crazy over this error.
UPDATE:
Still no luck, I have followed every step provided by solutions here below. perhaps this screenshot is of any help.
The main() function is corrected, but didn't help. I tried changing the path to the header files, im lost on this one. Does anyone perhaps have any alternatives to building this in xcode?
UPDATE2:
The suggestion worked, however now it is giving me this warning, which won't let me run the application.
Fixed! I removed the path in the build settings. Strange how I still don't know what went wrong, either way. thanks a lot for the help! made my day!
I see three possible problems. The first problem is how you're including SDL.h in your code. You should include SDL.h with the following code:
#include "SDL.h"
The second possible problem is you haven't added the files SDLMain.h and SDLMain.m to your project. Those files are necessary to compile SDL code on Mac OS X. The files are in the devel-lite folder on the SDL disk image.
The third possible problem is that your project doesn't link to the Cocoa framework. The Mac version of SDL uses Cocoa so you need the Cocoa framework in your project.
The following article walks you through the setup of an Xcode 4 project for SDL:
Using SDL with Xcode 4
UPDATE
I noticed a possible problem in how you defined the main() function. You have a space between char and * and another space between * and argv, which could be causing the error. The main() function in my SDL code is defined in the following way:
int main(int argc, char *argv[])
I'm trying to get into C++ programming, and I'm quite struggling against the little details. Right now, I'm trying to get the snippet below to work, and apparently it will compile, but not link. (error message is a the bottom of this post)
I'm using libsndfile to open audio files, and the linker doesn't seem to find the corrent library files for it. This is on OS X 10.5.
I've downloaded libsndfile from mega-nerd.com and installed it via the ususal configure, make, sudo make install procedure. Is there anything else I need to do?
Edit: I have macports installed on my system, if that's of any concern.
Here's my code:
#include <iostream>
#include <string>
#include <sndfile.h>
#include "stereoSplit.h"
using namespace std;
int stereoSplit(string filename)
{
cout << filename;
SF_INFO sfinfo;
sfinfo.format = 0;
SNDFILE * soundfile;
soundfile = sf_open( filename.c_str(), SFM_READ, &sfinfo );
return 0;
}
int main (int argc, char const *argv[])
{
return stereoSplit("testStereo.wav");
}
And here's the complete error message:
Undefined symbols:
"_sf_open", referenced from:
stereoSplit(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)in cc3hvkkk.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
You need to link in the library. Your compiler command should look something like:
g++ mystuff.cpp -lsndfile
To link the library in Xcode, select the project target, add a new item to Link binary with libraries, and find the libsndfile.1.dynlib on your computer.