Error: expected identifier or ‘(’ before ‘{’ token

This is a discussion on Error: expected identifier or ‘(’ before ‘{’ token within the C Programming forums, part of the General Programming Boards category; I just copy/pasted Jeff's code....

  1. #16
    Registered User
    Join Date
    May 2010
    Posts
    30
    I just copy/pasted Jeff's code.

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by jpcanaverde View Post
    I just copy/pasted Jeff's code.
    Jeff didn't provide any code in this thread. All he did was remove the extra curly brace you had in your code that prematurely ended main before you actually did anything.

  3. #18
    Registered User
    Join Date
    May 2010
    Posts
    30
    So... Now my error is other... Can you help me? :X Please?

  4. #19
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I don't have Allegro either. Check your documentation -- all I can say is the second argument of load_bitmap is pretty clearly not supposed to be a pointer-to-PALETTE.

    Just for you, I typed "allegro load_bitmap" into Google and got load_bitmap which pretty clearly shows what the second parameter is supposed to be.

  5. #20
    Registered User
    Join Date
    May 2010
    Posts
    30
    Ok, no errors compiling. But I'm having some trouble buiding.

    I have to build an .exe file. I tried numerous times, in Ubuntu with code blocks + allegro + mingw and in Windows with the same. But there's two different problems:

    In Ubuntu, I have trouble because I'm compiling to Windows. And I don't know what I did wrong, I followed numerous tutorials on tne net, and nothing.

    In Windows... It doesn't recognize Allegro, but it seems it would build fine with allegro...

    Somebody help, please? After this adventure... well, I have to study more.

  6. #21
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You need to actually use the Allegro libraries if you want to use them (which seems tautological, and it is). In C::B, you can specify the libraries for a project in the project options.

  7. #22
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by jpcanaverde View Post
    Ok, no errors compiling. But I'm having some trouble buiding.

    I have to build an .exe file. I tried numerous times, in Ubuntu with code blocks + allegro + mingw and in Windows with the same. But there's two different problems:

    In Ubuntu, I have trouble because I'm compiling to Windows. And I don't know what I did wrong, I followed numerous tutorials on tne net, and nothing.

    In Windows... It doesn't recognize Allegro, but it seems it would build fine with allegro...

    Somebody help, please? After this adventure... well, I have to study more.
    Well if you are VERY experienced, cross-compiling (what you are trying to so building on Ubuntu for Windows) is a tough experience (getting it set up properly). You know with just what you have going you could probably build FOR linux and see your program run sooner.

    Anyhow with Windows we don't know what you did to set up the library, where the headers/libraries are, etc but from the sounds of things getting new libs to run on Windows is a two-step process:
    1. Install the library using the installer that came with it.
    2. Tell your IDE where both the header files are and where the libraries are. I know almost nothing about CodeBlocks but generally there is a tab someplace which lets you add include paths (for where the Allegro H files are) and where to look for external libraries (which this is)..
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  8. #23
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by tabstop View Post
    Jeff didn't provide any code in this thread. All he did was remove the extra curly brace you had in your code that prematurely ended main before you actually did anything.
    Wait -- you didn't recognize that code as yours? Wow.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  9. #24
    Registered User
    Join Date
    May 2010
    Posts
    30
    Error:

    Code:
    >gcc -pedantic -Os -c main.c -o main.o -std=c99
    >Exit code: 0
    >make
    gcc -Wall -O3 -o main.exe main.c
    /tmp/ccFND2jH.o: In function `main':
    main.c:(.text+0x32): undefined reference to `_install_allegro_version_check'
    main.c:(.text+0x3e): undefined reference to `set_color_depth'
    main.c:(.text+0x6a): undefined reference to `set_gfx_mode'
    main.c:(.text+0x6f): undefined reference to `install_keyboard'
    main.c:(.text+0x7f): undefined reference to `load_bitmap'
    main.c:(.text+0x85): undefined reference to `screen'
    main.c:(.text+0x19a): undefined reference to `load_bitmap'
    main.c:(.text+0x1a0): undefined reference to `screen'
    main.c:(.text+0x1d9): undefined reference to `load_bitmap'
    main.c:(.text+0x1df): undefined reference to `screen'
    main.c:(.text+0x22c): undefined reference to `load_bitmap'
    main.c:(.text+0x232): undefined reference to `screen'
    main.c:(.text+0x2bb): undefined reference to `load_bitmap'
    main.c:(.text+0x2c1): undefined reference to `screen'
    main.c:(.text+0x426): undefined reference to `load_bitmap'
    main.c:(.text+0x42c): undefined reference to `screen'
    main.c:(.text+0x465): undefined reference to `load_bitmap'
    main.c:(.text+0x46b): undefined reference to `screen'
    main.c:(.text+0x4a4): undefined reference to `load_bitmap'
    main.c:(.text+0x4aa): undefined reference to `screen'
    main.c:(.text+0x533): undefined reference to `load_bitmap'
    main.c:(.text+0x539): undefined reference to `screen'
    collect2: ld returned 1 exit status
    make: ** [All] Erro 1
    >Exit code: 2
    In SciTE it doesn't give any errors compiling, but gives these ones building.

    And yes, I recognized my code, of course, but I thought that the changes you made with the brackets had solved my problem... I just want to build this... How can it be too hard?

  10. #25
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,658
    Quote Originally Posted by jpcanaverde View Post
    I just want to build this... How can it be too hard?
    It's not - you just don't know what the hell you're doing.

    Seriously, though, when you compile with dependencies, you have to do it in two steps: compile source files, then link, eg:

    gcc -optionA -optionB -c -o main.o main.c
    gcc -optionC -optionD -o main.exe main.o someLib1.a someLib2.a

    Also, you shouldn't be compiling outside of the makefile; one of it's purposes is to centralize everything in one place...



    ITSA
    Socket Library!

  11. #26
    Registered User
    Join Date
    May 2010
    Posts
    30
    What options and libs do I have to put? E typed this in Windows and Ubuntu:

    Code:
    gcc -Wall -c -o main.o main.c
    Code:
    gcc -Wall -o main.exe main.o libaldat.a liballd.a liballd_s.a liballeg.a liballeg_s.a liballp.a liballp_s.a
    On the first command, it doesn't return me anything... On the second, it says that the .a files don't exist. Weird...

    I don't need cross-compiling. I have Windows and Ubuntu... I compile on what's best for compiling the exe. If it is hard in Ubuntu, I compile in Windows... But I don't know how.

  12. #27
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,658
    Quote Originally Posted by jpcanaverde View Post
    What options and libs do I have to put? E typed this in Windows and Ubuntu:

    Code:
    gcc -Wall -c -o main.o main.c
    Code:
    gcc -Wall -o main.exe main.o libaldat.a liballd.a liballd_s.a liballeg.a liballeg_s.a liballp.a liballp_s.a
    On the first command, it doesn't return me anything... On the second, it says that the .a files don't exist. Weird...

    I don't need cross-compiling. I have Windows and Ubuntu... I compile on what's best for compiling the exe. If it is hard in Ubuntu, I compile in Windows... But I don't know how.
    You need to tell GCC what directory the library exists in. You can do that with the -L option, or simply supply the complete path along with the library name.



    ITSA
    Socket Library!

  13. #28
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by jpcanaverde View Post
    What options and libs do I have to put? E typed this in Windows and Ubuntu:

    Code:
    gcc -Wall -c -o main.o main.c
    Code:
    gcc -Wall -o main.exe main.o libaldat.a liballd.a liballd_s.a liballeg.a liballeg_s.a liballp.a liballp_s.a
    On the first command, it doesn't return me anything... On the second, it says that the .a files don't exist. Weird...

    I don't need cross-compiling. I have Windows and Ubuntu... I compile on what's best for compiling the exe. If it is hard in Ubuntu, I compile in Windows... But I don't know how.
    Well if you are on Ubuntu and compiling an EXE (Windows app), you *are* cross-compiling Ace. If you just built this for Ubuntu on Ubuntu to run on Ubuntu, you would be done by now. Seriously. If you need help with that, I and others are more than ready to help. Compiling on Ubuntu to run on Windows is (in my universe) a waste of time so I don't mess with cross-compiling in that way. Cross compiling for ARM or motorola 68K, or CellBE, that has a purpose. As a test I may take your latest source, install allegro and build it on Ubuntu (10.04 as of two nights ago) just to A, see what this creation of yours actually is and B to see how fast it will go. I am guessing if your latest source even compiles I will have a running executable in less than an hour.

    OP: is it still pretty much as I posted it a few days ago?
    Last edited by jeffcobb; 05-22-2010 at 02:20 PM. Reason: Added q for OP
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  14. #29
    Registered User
    Join Date
    May 2010
    Posts
    30
    I'm sending you a PM with the source then. Thank you very much. If you can compile with Ubuntu, then I'l compile with Windows with the changes... I really need an .exe, because it's for school, and school uses Windows.

    Wait... I think they have a laptop with Alinex dual-booted... I might show the program to the teacher there. Yay, don't need to compile to .exe, after all.

    P.S. I don't post the source here because it has personal details... I'l post the final code with the details hidden, so I can help people with the same problem.

    THANK YOU.

  15. #30
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    OK Took your source code, made a couple of small changes and it now builds and runs on Ubuntu. It doesn't run *well* but I have no idea what you are trying to make it do (I am more of a systems dude). However sorting out your program logic is an exercise left for the OP. First, I did not use your libraries as humping those things around is a PITA. On Ubuntu just:
    Code:
    sudo apt-get install liballegro4.2-dev
    <enter your password at the prompt>
    This will install the libraries at the right places in your system and configure the linker lookup table (usually done with ldconfig but handled for you by the APT package system). I don't know how old your Ubuntu is but if that version of the library is not available, just do an apt-cache search liballegro and find the version that is available to you.

    Now that the libraries are installed...

    The changes are:

    In your makefile do this:
    Code:
    All:
    	gcc -Wall -O3 -o main.exe main.c `allegro-config --libs`
    That last bit is using a tool on your system called pkg-config. Its handy for sorting out where various libraries are if they are installed in non-standard places. If you don't have it installed, then:
    Code:
    sudo apt-get install pkg-config
    I do a lot of programming so have lots of stuff already installed.

    OK onto the rest of the changes:

    in main.c:
    Add this just *after* your closing brace on main. I know its goofy but its some kind of squirrely hack the allegro people came up with: END_OF_MAIN()
    So your main.c ends like this:
    Code:
       getchar();
       return 0;
    }
    END_OF_MAIN()
    Lets see, what else...I guess thats it. Write if you have issues and I can send you a patch file to make these changes but they are pretty simple.

    Time for lunch..

    UPDATE: I meant to mention: 1. sticking an .exe on a unix executable doesn't help or hurt anything physically but it is a kind of noob thing to do. 2. This runs on my box, flits around with my resolution and then stops but I think it has more to do with how the Allegro tools are being used. Thats just a guess but I don't have a lot of time to sink into this right now, working on my own monstrosity..
    Last edited by jeffcobb; 05-22-2010 at 03:32 PM.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Page 2 of 5 FirstFirst 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21