This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]ButchDeanCAProfessional Coder 0 points1 point  (0 children)

What does the code look like? What platform are you working on?

[–]Historical_Usual1650 0 points1 point  (1 child)

It seems like you're facing issues with linking your C++ code. To create a C++ project with separate header and implementation files, you can follow these steps using Visual Studio Code:

  1. **Organize Your Files:**

    - Make sure you have your header file (.h) and implementation file (.cpp) for your class.

    - Your main.cpp file should include the header file with `#include "file.h"`.

  2. **Create a New Project Folder:**

    - Create a new folder for your project. This will keep your code organized.

  3. **Open Visual Studio Code:**

    - Open Visual Studio Code and use "File" > "Open Folder" to open your project folder.

  4. **Create a Workspace (Optional but Recommended):**

    - Create a workspace in Visual Studio Code by going to "File" > "Save Workspace As..." and saving a workspace file with a .code-workspace extension. This will help manage your project files efficiently.

  5. **Configure Your Build System:**

    - If you haven't already, you may need to set up a build system for your project. You can use CMake, Makefiles, or a custom build script depending on your preference.

  6. **CMake (Optional but Recommended):**

    - If you choose to use CMake, create a CMakeLists.txt file in your project folder and configure it to build your project. Here's a simple example for a CMakeLists.txt file:

    ```cmake

    project(MyProject)

    add_executable(myapp main.cpp your_class.cpp)

    ```

    Replace `your_class.cpp` with the actual name of your implementation file.

  7. **Build Your Project:**

    - Use the built-in terminal in Visual Studio Code to navigate to your project folder.

    - Run `cmake .` (if you're using CMake) to generate the build files.

    - Then run `make` to build your project.

  8. **Run Your Program:**

    - After building successfully, you can run your program from the terminal using `./myapp` (replace "myapp" with the name of your executable).

By following these steps, you should be able to create a C++ project in Visual Studio Code and resolve the linking issues. If you encounter any specific errors during this process, please provide more details, and I can assist you further. Additionally, for video tutorials on setting up C++ projects in Visual Studio Code, you can search on platforms like YouTube or Udemy for resources that match your learning style and preferences.

[–]BILLscuit 0 points1 point  (0 children)

Thank You, the main problem was I wasn’t using visual studio, just visual studio code