Один определенный класс C ++ не собирается во время процесса сборки Visual Studio - PullRequest
0 голосов
/ 07 июня 2019

Низкий

Я создаю свою собственную библиотеку классов C ++ для работы с некоторым кодом SDK, который я скачал из репозитория github . Эта дополнительная библиотека классов, которую я назвал «Hogwash» (это длинная история), работает просто отлично, за исключением одной проблемы: мой класс «Average», который предоставляет простой объект для добавления чисел к совокупному среднему значению перед «Get» () "- с помощью усреднения и очистки объекта просто отказывается от компиляции. Я получаю ошибки компоновщика для каждого вызова функции, который я ему выполняю.

Я обнаружил прекрасно описательную страницу ошибки для LNK2019, одну из ошибок, которые я получаю (это только я, или этот год преследует меня?), Которая упоминает, что потенциальная причина моей ошибки могут быть следующими: при первом запуске компилятора (который преобразует предварительно обработанный код в код .obj) файл не компилировался, поэтому, когда пришло время для компоновщика, этот файл не существовал. Просматривая результаты сборки, я обнаружил, что это так. Произошел весь процесс сборки, и все .cpp файлы были названы по одному, кроме ... нет Average.cpp

Единственная информация, которую Интернет имел для меня, была эта статья , в которой упоминается разделение файлов .h и .cpp на две части, что, конечно, я уже сделал по соглашению. Я попытался удалить и повторно добавить файл проблемы, на случай, если проблема связана с метаданными файла Visual Studio, и это буквально не дало результата. Я попытался полностью удалить проект, создать новый проект C ++ и заново добавить все файлы моего проекта, но ничего не изменилось.

Так что я застрял. Есть ли у меня мудрее идеи?


Полезные вещи

Вывод компилятора:

1>------ Rebuild All started: Project: Hogwash, Configuration: Debug Win32 ------
1>  Stdafx.cpp
1>  AssemblyInfo.cpp
1>  HogwashAlgorithm.cpp
1>HogwashAlgorithm.cpp(76): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
1>  ProcessScanResult.cpp
1>  Generating Code...
1>  .NETFramework,Version=v4.5.2.AssemblyAttributes.cpp
1>  AssemblyInfo.obj : /DEBUG:FASTLINK is not supported when managed code is present; restarting link with /DEBUG:FULL
1>HogwashAlgorithm.obj : error LNK2028: unresolved token (0A000165) "public: void __thiscall Average::Add(float)" (?Add@Average@@$$FQAEXM@Z) referenced in function "public: static class ProcessScanResult __cdecl Hogwash::HogwashAlgorithm::ProcessScan(class std::vector<struct scanDot,class std::allocator<struct scanDot> >)" (?ProcessScan@HogwashAlgorithm@Hogwash@@$$FSA?AVProcessScanResult@@V?$vector@UscanDot@@V?$allocator@UscanDot@@@std@@@std@@@Z)
1>HogwashAlgorithm.obj : error LNK2028: unresolved token (0A000166) "public: __thiscall Average::Average(void)" (??0Average@@$$FQAE@XZ) referenced in function "public: static class ProcessScanResult __cdecl Hogwash::HogwashAlgorithm::ProcessScan(class std::vector<struct scanDot,class std::allocator<struct scanDot> >)" (?ProcessScan@HogwashAlgorithm@Hogwash@@$$FSA?AVProcessScanResult@@V?$vector@UscanDot@@V?$allocator@UscanDot@@@std@@@std@@@Z)
1>HogwashAlgorithm.obj : error LNK2019: unresolved external symbol "public: __thiscall Average::Average(void)" (??0Average@@$$FQAE@XZ) referenced in function "public: static class ProcessScanResult __cdecl Hogwash::HogwashAlgorithm::ProcessScan(class std::vector<struct scanDot,class std::allocator<struct scanDot> >)" (?ProcessScan@HogwashAlgorithm@Hogwash@@$$FSA?AVProcessScanResult@@V?$vector@UscanDot@@V?$allocator@UscanDot@@@std@@@std@@@Z)
1>HogwashAlgorithm.obj : error LNK2019: unresolved external symbol "public: void __thiscall Average::Add(float)" (?Add@Average@@$$FQAEXM@Z) referenced in function "public: static class ProcessScanResult __cdecl Hogwash::HogwashAlgorithm::ProcessScan(class std::vector<struct scanDot,class std::allocator<struct scanDot> >)" (?ProcessScan@HogwashAlgorithm@Hogwash@@$$FSA?AVProcessScanResult@@V?$vector@UscanDot@@V?$allocator@UscanDot@@@std@@@std@@@Z)
1>C:\Users\lucas\Desktop\HogWash\rplidar_sdk-master\rplidar_sdk-master\sdk\workspaces\vc10\Debug\Hogwash.dll : fatal error LNK1120: 4 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

(Весь) файл проекта Hogwash.vcxproj:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{69E4290E-77ED-443A-A2D7-ECD4B223E5C6}</ProjectGuid>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <Keyword>ManagedCProj</Keyword>
    <RootNamespace>Hogwash</RootNamespace>
    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <CLRSupport>true</CLRSupport>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <CLRSupport>true</CLRSupport>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <CLRSupport>true</CLRSupport>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <CLRSupport>true</CLRSupport>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeader>Use</PrecompiledHeader>
    </ClCompile>
    <Link>
      <AdditionalDependencies />
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeader>Use</PrecompiledHeader>
    </ClCompile>
    <Link>
      <AdditionalDependencies />
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeader>Use</PrecompiledHeader>
    </ClCompile>
    <Link>
      <AdditionalDependencies />
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeader>Use</PrecompiledHeader>
    </ClCompile>
    <Link>
      <AdditionalDependencies />
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="HogwashAlgorithm.h" />
    <ClInclude Include="ProcessScanResult.h" />
    <ClInclude Include="resource.h" />
    <ClInclude Include="scanDot.h" />
    <ClInclude Include="Stdafx.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="AssemblyInfo.cpp" />
    <ClCompile Include="HogwashAlgorithm.cpp" />
    <ClCompile Include="ProcessScanResult.cpp" />
    <ClCompile Include="Stdafx.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <Text Include="ReadMe.txt" />
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="app.rc" />
  </ItemGroup>
  <ItemGroup>
    <Image Include="app.ico" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

Единственная ссылка, которую я сейчас делаю, на Average.h (и его окружение):

// This is the main DLL file.

#include "stdafx.h"
#include "resource.h"
#include <math.h>
#include "HogwashAlgorithm.h"
#include "ProcessScanResult.h"
#include "Average.h"


using namespace std;
using namespace Hogwash;

#ifndef HOGWASH_ALGORITHM_H
#define HOGWASH_ALGORITHM_H

...

Average.h

#pragma once

#include <vector>

class Average
{
public:
    Average();
    std::vector<float> * numList;
    int count;
    // Add to the current Average
    void Add(float Number);
    // Finish the Average Operation, return the average, and clear the object for a new averaging operation
    float Get();
};

Average.cpp

#include "Average.h"
#include "Stdafx.h"
#include <numeric>

Average::Average()
{
    this->numList = new std::vector<float>(0);
    this->count = 0;
}

// Add to the current Average
void Average::Add(float Number)
{
    this->numList->push_back(Number);
    this->count++;
}

// Finish the Average Operation, return the average, and clear the object for a new averaging operation
float Average::Get()
{
    float average;
    if (count == 0) {
        average = 0;
    }
    else {
        float average = std::accumulate(this->numList->begin(), this->numList->end(), 0) / this->count;
    }
    this->numList = new std::vector<float>(0);
    this->count = 0;
    return average;
}
...