_main not defined on Mac OS X 10.11 in c++ - c++

I am currently writing a c++ game using allegro 5.0 and c++. I will eventually get it working on mac, linux, windows, and possibly android and iPhone. Currently it compiles and runs on linux (tested on arch linux latest), but on mac there is a slight problem:
Using the apple provided g++, it complains about a linking error, _main not defined. However, I have checked and checked, and main is definitely defined in my file. It must be anyway because it compiles and runs on linux, but I can't figure it out.
I have googled many many days and many many terms (too many to list) and haven't found anything to do with mac and main not being defined. Could there be something I'm missing? Something i need to do special on mac? One last thing to note is when I link with allegro_main.a it links, but then crashes. Linking with this library is not necessary on linux. I am using allegro5 through macports. It is also useful to note that the sh script used to compile on mac is comp_mac.sh, and linux is simply comp.sh. Note that you may need to modify the sh script(s) to compile on your environment. These are only tested on my environment (macports) so far.
My code can be found here: http://github.com/2mb-solutions/horseshoes/
Thanks for all the help I can get.
-Michael.

The "_main" undefined symbol error is occurring because you are not linking with the allegro_main addon.
As the Allegro 5 manual specifies, in C and C++ projects, the file containing your main() function must include the core header allegro5/allegro.h. Additionally, you must link with the allegro_main addon.
It might be easiest to use pkg-config:
pkg-config --cflags --libs allegro-5 allegro_ttf-5 allegro_audio-5 allegro_acodec-5 allegro_font-5 allegro_main-5
You can place that command within backticks ( ` ) to include the output of pkg-config in your build command.

Related

SFML Undefined symbols for architecture arm64 [duplicate]

I have MacBook Air with m1 chip and tried to install SFML according to the instructions on the official website however I can not compile the project for example
enter image description here
EDIT: I moved the Xcode app act via rosetta 2 and now it works I would love to know if there is a solution that will activate it natively
The error you are receiving is telling you that the version being linked is for MacOS on x32_64, while trying to compile for arm64. This is incompatible, given they're two different platforms.
Are you compiling SFML from source? It doesn't look like SFML has precompiled binaries for MacOS-arm64, but the source code does have arm compatibility. Compiling from source would be operating system agnostic as long as everything is there (and supports arm64.) SFML has an article on how to compile from source with CMake: https://www.sfml-dev.org/tutorials/2.5/compile-with-cmake.php
While I can't guarantee this will fix your issue, it's definitely worth a try if you haven't yet.
The reason using Rosetta made this work is because Rosetta emulates some parts of x32_64. Running these apps in Rosetta would essentially be the same as compiling your project on an Intel based Mac.
I found the solution if it can help some, just make your pc believe that you have an intel chip, by adding /usr/bin/arch -x86_64 before your order.
example:
/usr/bin/arch -x86_64 clang main.c -lcsfml-graphics -lcsfml-system

Using SFML for Codeblocks C++ appears ERROR library SFML

I have a problem when I tried to install SFML on Codeblocks. Well, first I install codeblocks: codeblocks-20.03mingw-setup.exe . That's compile correctly after that I download SFML 2.5.1: GCC 5.1.0 TDM (SJLJ) - Code::Blocks - 32-bit.
Following, I extract the SFML file.The problem comes I COPY THE CONTENT OF "BIN" INSIDE OF MY CODEBLOCKS PROJECT. A video helps me to do all of before, I WROTE ALL THE LIBRARIES: GRAPHICS, WINDOW, NETWORK, AUDIO, SYSTEM BUT NOTHING. I show you the error:
cannot find -lsfml-audio-d-2
And continue with network, window,system, graphics
At the ends:
error: ld returned 1 exit status
what's wrong? help me please. I have to make a video game using CODEBLOCKS as soon as I fixed this problem. I'll so thankful for your answers.
On the SFML download website (https://www.sfml-dev.org/download/sfml/2.5.1/), it says:
The compiler versions have to match 100%!
The CodeBlocks 20.03 MinGW installation includes version 8.1.0 of the GCC compiler (as is stated on the download page: http://www.codeblocks.org/downloads/26).
Your downloaded version of SFML thus is only intended to work with version 5.1.0 of GCC, but you have version 8.1.0. This can result in a number of errors.
There are a few possibilities to fix your issue:
You could theoretically compile SFML yourself with your specific compiler, but this option may be quite complicated.
You could use a compiler with the matching version. On the SFML download website, there are some links to the needed compilers. After having installed a compiler, you will have to configure CodeBlocks to detect the new compiler on your system (reference: Adding compiler to code::blocks). Now, in order to add SFML to your project, I would suggest to use this official guide:
https://www.sfml-dev.org/tutorials/2.5/start-cb.php
You could use an environment like MSYS2 (which I use personally) to have a package manager to manage your compiler and libraries installations. This way, your compiler installation and your libraries should work with each other. But in order to use this compiler in CodeBlocks, CodeBlocks would have to be configured.
I would suggest that you refer to option 2 because it probably is the quickest solution.
Feel free to ask if you have any more questions. I know from personal experience that setting up SFML (or any other C++ library) to work with your IDE may be quite tricky.

Using GTK+ without MSYS2

Dear programmers and developers,
I really want to try out GTK+ 3 on windows. Therefore, I read the official GTK+ download explanations at https://www.gtk.org/download/windows.php and installed everything with MSYS2.
Now I have a lot of files in my mingw64 subdirectory of my MSYS2 folder.
The question: How do I include all of them right? How do I link to GTK+ with all it's dependencies? I know there is a magic pkg-config attribute for the Linux C/C++ compiler, but unfortunately I am really not interested in compiling my projects in MSYS2. I am willing to use a simple MinGW (64) compiler.
Can anybody help me using the .a's, .h's and .dll'a that MSYS2 generated with a simple MinGW 64bit compiler for a stupid C++ project?
It would make me extremely happy!
Darth Moon
€edit: I actually have downloaded a precompiled GTK+ version from https://www.dropbox.com/sh/8d1qbh5dsp044on/AAB63l5I1eZks-QqjH6HXUJHa. Unfortunately, it is only 32bit but I will soon try to compile the whole GTK+ project on myself like this guy at https://github.com/Wesley-Chan/GTK-for-Windows did.
But if anybody has any idea how to build GTK+ in a smooth way under windows (especially for 64bit), please let me know! I really enjoyed the GTK+ example application and I really want to make my own ones!
I was able to successfully compile a GTK3 program in a MinGW 64-bit shell from MSYS2. First I installed the GTK3 package:
pacman -S $MINGW_PACKAGE_PREFIX-gtk3
Then I compiled the first example program from this page using the following command:
gcc test_gtk.c $(pkg-config gtk+-3.0 --cflags --libs)
Then I ran ./a.exe and it created a window.
If you are getting "undefined reference" linker errors, it means your Makefile is not linking your program to all of the correct libraries, or the order of the inputs to the linker is wrong.

Install gcc 4.9 on windows and configure it in Netbeans

Preamble
If anything I wrote is not correct, please be so kind and correct me. I am a php developer mainly - I am not into this compiling stuff. I know there are a lot of topics around the www but they seems to be either old/outdated, very complex or links to a bunch of files on sourceforge (I have no clue what files I should download and what to do with them after downloading them).
Searching a couple of days by now
I am researching for a couple of days by now and tried different compilers and settings but I don't get a standalone executable for a c++14 programme.
First compiler
The first compiler I used was cygwin. I was able to compile it with c++14 but on other computers cygwin had to be installed as well as a cygwin dll was missing. I googled and figured out that programmes compiled using Cygwin requires this dll but cannot be included to the programme itself - or did I missed something?
Current compiler
I then switched to MinGW which seems to be a better choice as it allows to compile standalone executables which is correct as I am able to do so. Well, the MinGW setup I downloaded from http://www.mingw.org/ installed among other the gcc version 4.8.1. I need 4.9.1 for c++14.
As the title says I want to configure it in Netbeans but if there is a proper tutorial for a command line compiling it's no problem either but I try to avoid using another IDE as we use it at work, too.
drangon.org
I also heard about http://www.drangon.org/mingw/ but there are tons of links linking to similiar stuff.
My goals
Get a better understanding about gcc and this compiling stuff in general.
Install gcc 4.9.1 (preferred into MinGW as it's currently installed)
Configure it in Netbeans 8.
I suggest you to try MinGW-w64. (Download.)
It's similar to MinGW, but have better multitreading support, can easily compile x64 applications, and what's more important, at this moment it uses GCC 4.9.2.
By the way, MinGW applications require some .dlls to work too. Usually you just provide these libraries with your application, but another option is to add -static flag at linking phase. Applications that are compiled with it do not require any external library files (unless you're using 3rd party libraries that don't support static linking).

Deploy OSX application compiled using GCC 4.6

I'm trying to port a project of mine on Mac OS-X.
As I developed my project using C++0X I needed a more recent version of GCC than the one provided with Xcode (even Xcode4), so I compiled GCC 4.6 on my Snow Leopards Mac.
My project does compile fine and it does start too on the computer I compiled it (OS-X 10.6.7) but when I transfer it to my MacBook (OS-X 10.5.8) it doesn't works.
It returns the following errors:
dyld: lazy symbol binding failed:
Symbol not found:
__ZNSo9_M_insertImEERSoT_ Referenced from:
/Users/zu/Desktop/OgreApp.app/Contents/MacOS/OgreApp
Expected in:
/usr/lib/libstdc++.6.dylib
dyld: Symbol not found:
__ZNSo9_M_insertImEERSoT_ Referenced from:
/Users/zu/Desktop/OgreApp.app/Contents/MacOS/OgreApp
Expected in:
/usr/lib/libstdc++.6.dylib
I understand that the program needs the libstdc++.6.dylib of the GCC 4.6.0 as this file contains the C++0x functions (despite the fact that my current test doesn't use any C++0x function) instead of the standard libstdc++.6.dylib usually included in the OS-X system.
So I tried the following:
to specify -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 in order to ensure backward compatibility with OS-X 10.5. But the error remains the same.
to verify the libstdc++.6.dylib path using otool -L and changing the shared library path using install_name_tool -change /opt/local/lib/gcc46/libstdc++.6.dylib #executable_path/../Libraries/libstdc++.6.dylib OgreApp (with a copy of the gcc 4.6.0 libstdc++.6.dylib in the Libraries folder) as suggested as answer of my previous question. But the error remains the same.
to statically link libstdc++ and libgcc using -static-libgcc - static-libstdc++. But it still returns the same error.
As my program use the Ogre framework, I applied the above manipulations to the Ogre executable embedded in the Ogre.framework too, but it doesn't change anything.
Does anyone can explain me how I'm supposed to deploy an application created with a non standard libstdc++ on another Mac computer installed with an older version (I guess the problem is the same with a computer running Snow Leopard as the program use the GCC 4.6.0 libstdc++) ?
Mac OS X 10.5 does not include a compatible copy of the GCC standard library. If you want your code to run on Leopard, you'll have to either modify it to compile under an older version of GCC, or you'll have to... well, really that's your only option.