-1

I'm encountering a linking issue and I'm hoping to get some help here. I have a project that includes a header file app.h and a source file app.cpp. I've declared a class dev in app.h, and within it, I've declared a function ksb. I've implemented this function in app.cpp. My goal is to use this function in another project, but I'm encountering issues during the linking phase.

Here's an example of the code in app.h:

#pragma once
#include <Windows.h>

class dev
{
public:
    int a, b;

    int fun(int b, int c)
    {
        return b + c;
    }

    int ksb(int s, int b); // Function declaration
};

I've implemented the ksb function in app.cpp, and I've confirmed that this file is compiled correctly. Here's an example of my app.cpp:

#include "app.h"

int dev::ksb(int s, int b)
{
    return s * b;
}

Then, in another project, I've included app.h and tried to call the ksb function in my code. However, during the linking phase, I'm encountering an issue where it can't find the implementation of the ksb function.

I've tried the following steps to resolve the issue:

Ensuring that app.cpp is compiled into a target file correctly. Including the correct header file directories and settings. Checking for namespace and scope issues. Cleaning and rebuilding the entire project. However, the issue persists. I'm wondering if there's something else I might be missing or if there's another approach to resolving this problem.

Any help or guidance would be greatly appreciated! Thank you!

I've taken the following steps to troubleshoot the issue:

Compiled app.cpp into a target file successfully. Ensured that the correct header file directories and settings are included in the project. Checked for potential namespace and scope conflicts. Cleaned the project and rebuilt it to ensure a fresh build. I expected that after completing these steps, the project in which I'm trying to use the ksb function would successfully link to its implementation and resolve the issue.

However, despite these efforts, I'm still encountering the linking issue where the linker cannot find the implementation of the ksb function when trying to use it in the other project. This results in linker errors during the compilation process.

  • Including app.h just makes the compiler to be aware of the declarations of the class methods. You still need to compile app.cpp for making the linker to be aware of the definitions of the class methods in your another project. – 273K Aug 26 '23 at 07:29

0 Answers0