Global mySQL connection function

This is a discussion on Global mySQL connection function within the C++ Programming forums, part of the General Programming Boards category; The Code + Errors I tried to use the extern keyword but that didn't work. All I want is a ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    8

    Global mySQL connection function

    The Code + Errors


    I tried to use the extern keyword but that didn't work. All I want is a global function I can call that connects to mysql for me. Any idea's on how to fix the above?

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    It doesn't sound like a proper use of extern... Though I didn't even read the code.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Code in header file bad. That is what the complaints are about. Pick a .cpp file to put it in.

    charset should be extern in the header, and defined in whatever .cpp file is appropriate (but only once!)

    And indeed you don't use the variable mysql in your find thing, so ... yeah. (It's not the same one as in your .h file.)

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    8
    The code listed is before I tried the extern. I was hoping some one could point me in the right direction on if the extern would be the best option or if there is another solution.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    8
    Updated Code

    I updated it with trying to use extern. I managed to get it "working" at one point but my program crashed when accessing mysql but not sure what I had then.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Functions aren't ever extern. The dlgcustomer.cpp file you posted doesn't even have 135 lines in it, so who knows what's going on there.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    8
    So do you have a suggestion on how to get this working?

    I know, I cut out some of the wxWidgets code to shorten it down. I just wanted the errors to be seen.

    Functions aren't ever extern.
    What do you mean by this? From what I have found from google you can do extern void myFunc() just fine.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well you can put the word "extern" in front of a prototype, yes. Since it already is a prototype, you're not adding anything. I wouldn't say that functions have linkage like objects do.

    Is it a compile-time or link-time error? It looks like everything's #included correctly. The point about line 135 is that the function name is used elsewhere in the function, unless you only are showing us line 135.

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    8
    I want to say link - at home at the moment so can't double check.

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So, I have to backtrack a little bit; functions have linkage too; the standard says this:
    Quote Originally Posted by ISO C 6.2.2
    If the declaration of an identifier for a function has no storage-class specifier, its linkage
    is determined exactly as if it were declared with the storage-class specifier extern. If
    the declaration of an identifier for an object has file scope and no storage-class specifier,
    its linkage is external.
    So there you go -- extern by default.

    Anyway, link seems likely. Check if you even have a dbconnect.o; if not, it's definitely not in your project; if so, either somehow it's not getting linked or it's not in your project but you compiled it separately at some point.

  11. #11
    Registered User
    Join Date
    Oct 2008
    Posts
    8
    i'm 99.9999% it's part of the project - I'll look for the dbconnect.o

  12. #12
    Registered User
    Join Date
    Oct 2008
    Posts
    8
    The way it was when I posted the updated code it was a compiler error not linker

  13. #13
    Registered User
    Join Date
    Oct 2008
    Posts
    8
    Aight, now that I'm back at work I figured it out. Thanks a ton. It was a linker error (had something commented out that I didn't notice so it looked like a compiler error) The .cpp wasn't being compiled or linked but now that it is it is working like a charm!

  14. #14
    Hacker MeTh0Dz's Avatar
    Join Date
    Oct 2008
    Posts
    111
    Function prototypes default to extern, but you can use static to limit their scope.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Replies: 3
    Last Post: 03-04-2005, 01:46 PM

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