Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Makefile not compiling the oauth2 module #76

Merged
merged 1 commit into from
Jul 25, 2022
Merged

Fix Makefile not compiling the oauth2 module #76

merged 1 commit into from
Jul 25, 2022

Conversation

jdeokkim
Copy link
Contributor

What?

This pull request fixes a bug where Makefile would not compile the oauth2 module in src directory when the make command is invoked.

Why?

Environment

$ uname -srvmpio
Linux 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Description

  1. Clone this repository and install the latest development version
$ git clone https://github.com/Cogmasters/concord && cd concord
$ git checkout dev 
$ make -j`nproc`
$ sudo make install
  1. Build a small bot example that uses discord_get_current_bot_application_information()
#include <string.h>

#include <concord/discord.h>
#include <concord/log.h>

#include <pthread.h>

#define CONFIG_PATH "res/config.json"

void on_complete(
    struct discord *client, 
    struct discord_response *resp, 
    const struct discord_application *ret
);

void *read_input(void *arg);

int main(int argc, char *argv[]) {
    ccord_global_init();

    struct discord *client = discord_config_init(
        (argc > 1) ? argv[1] : CONFIG_PATH
    );

    pthread_t thread;
    pthread_attr_t attr;

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    pthread_create(&thread, &attr, &read_input, client);

    pthread_attr_destroy(&attr);

    discord_run(client);

    discord_cleanup(client);

    ccord_global_cleanup();
}

void on_complete(
    struct discord *client, 
    struct discord_response *resp, 
    const struct discord_application *ret
) {
    printf(
        "%s#%s\n", 
        ret->owner->username,
        ret->owner->discriminator
    );
}

void *read_input(void *arg) {
    struct discord *client = arg;

    char buffer[DISCORD_MAX_MESSAGE_LEN + 256];

    for (;;) {
        memset(buffer, 0, sizeof(buffer));

        fgets(buffer, sizeof(buffer), stdin);

        buffer[strcspn(buffer, "\r\n")] = 0;

        if (buffer[0] == '\0') continue;

        struct discord_ret_application ret = { 
            .done = on_complete
        };

        discord_get_current_bot_application_information(
            client, 
            &ret
        );
    }

    pthread_exit(NULL);
}
  1. It won't compile!
$ gcc src/main.o -o bin/c-lab -D_DEFAULT_SOURCE -g -Iinclude -Isrc/external \
-O2 -std=gnu99 -ldiscord -lcurl -lpthread

/usr/bin/ld: src/main.o: in function `read_input':
(...)/c-lab/src/main.c:93: undefined reference to `discord_get_current_bot_application_information'
collect2: error: ld returned 1 exit status
make: *** [Makefile:62: bin/c-lab] Error 1

How?

Like this!

Testing?

$ cd c-lab
$ make clean && make
jdeokkim/c-lab: Cleaning up.
jdeokkim/c-lab: Using: 'gcc' to build this project.
jdeokkim/c-lab: Compiling: src/main.o (from src/main.c)
jdeokkim/c-lab: Linking: bin/c-lab
jdeokkim/c-lab: Build complete.

@lcsmuller lcsmuller merged commit 1e4b302 into Cogmasters:dev Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants