Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:32:06+00:00 2026-06-07T14:32:06+00:00

I have these 2 c file and a header file. All these files are

  • 0

I have these 2 c file and a header file. All these files are built by a Makefile.

mysql_storage.h

#include <stdio.h>
#include <mysql.h>
#include <glib/gstdio.h>

#if 1
typedef enum {
        STORAGE_OK = 0,
        STORAGE_NO_SUCH_USER,
        STORAGE_INVALID_PASSWORD,
        STORAGE_ALREADY_EXISTS,
        STORAGE_OTHER_ERROR/* Error that isn't caused by user input, such as 
                               a database that is unreachable. log() will be 
                               used for the exact error message */
} storage_status_t;

typedef enum
{
    MYSQL_PASS_CHECK_ONLY = -1,
    MYSQL_PASS_UNKNOWN = 0,
    MYSQL_PASS_WRONG,
    MYSQL_PASS_OK
} mysql_pass_st;
#endif

static void mysql_storage_init( void );
static void mysql_storage_deinit( void );
static storage_status_t mysql_storage_load(const char *password );
static storage_status_t mysql_storage_check_pass( const char *nick, const char *password );
static storage_status_t mysql_storage_save( int overwrite );
static storage_status_t mysql_storage_remove( const char *nick, const char *password );

mysql_storage.c

#include "mysql_storage.h"

MYSQL *mysql;

static void mysql_storage_init( void ) {
    if (mysql_init(mysql) == NULL)
        fprintf( stderr, "Can not initialize MySQL. Configuration won't be saved.");

    if (!mysql_real_connect(mysql, "localhost", "USERNAME", "PASSWORD", NULL, 3306, NULL, 0))
        fprintf( stderr, "%s\nConfiguration won't be saved.", mysql_error(mysql));

    if (mysql_select_db(mysql, "DATABASENAME"))
        fprintf( stderr, "%s\nConfiguration won't be saved.", mysql_error(mysql));
}
static void mysql_storage_deinit( void ) {
    if(mysql!=NULL) 
        mysql_close(mysql);
}
static storage_status_t mysql_storage_check_pass( const char *nick, const char *password ){    return STORAGE_OTHER_ERROR;}
static storage_status_t mysql_storage_load(const char *password ){    return STORAGE_OTHER_ERROR;}
static storage_status_t mysql_storage_save( int overwrite ){    return STORAGE_OTHER_ERROR;}
static storage_status_t mysql_storage_remove( const char *nick, const char *password ){    return STORAGE_OTHER_ERROR;}

main.c

#include<stdio.h>
#include "mysql_storage.h"

    int main(){
        // connect mysql
        mysql_storage_init();
        // check a password
        printf("check password: %d\n:", mysql_storage_check_pass("hello", "world"));
        // close mysql
        mysql_storage_deinit();
    }

Lastly the Makefile

CFLAGS=-I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -g -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I.
LIBS=-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl -lglib-2.0 -L.
CC=gcc

all: main
clean:
        rm main  *.o
main: mysql_storage.o main.o 
        $(CC)  main.o mysql_storage.o $(LIBS) -o main
.c.o:
        $(CC) -c $(CFLAGS) $<

When I make, I get this error.

gcc  main.o mysql_storage.o -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl -lglib-2.0 -L. -o main
main.o: In function `main':
/home/shiplu/projects/mysql_interface/main.c:8: undefined reference to `mysql_storage_init'
/home/shiplu/projects/mysql_interface/main.c:11: undefined reference to `mysql_storage_check_pass'
/home/shiplu/projects/mysql_interface/main.c:15: undefined reference to `mysql_storage_deinit'
collect2: ld returned 1 exit status

As you can see I am linking main.o and mysql_storage.o. So it should not throw undefined reference error. What is the problem here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:32:12+00:00Added an answer on June 7, 2026 at 2:32 pm

    You declared your functions mysql_storage_init as static, meaning they have internal linkage — this means they are not visible to other translation units.

    Since you need to call them from other object files, you should instead declare them to have external linkage by omitting the static keyword in their declarations and definitions. The prototypes in the header file may optionally declare them extern, but that is not required, since the linkage is external by default.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C makefile which generates header file from java code and compiles
I have a header file buildTree.h and a C file buildTree.c there is a
I have these 3 file in my program: sample1.h (method in sample1.cpp are defined
I have these a coffeescript file for a model entree that just instanciates a
I have these in a jsp file. But these values are not updated in
I have these (sample) lines in a HTML-file: test.ABC.test test.ABCD.test test.ABCE.test And this Ant
i have 2 file js in my asp website named 1-jquery.datepick.js 2-jquery.hijridatepick.js these file
I have these methods. I have defined a char array in stringcontent.h file and
Iam making an app which has one index.php file. I also have these other
Did not have luck with these examples: Javascript File remove Javascript FSO DeleteFile Method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.