C++ 오류: LINK2005
高洛峰
高洛峰 2017-05-16 13:23:40
0
1
577
  1. 문제 설명
    common.h은 모든 유형 별칭과 구조 선언을 정의하며 mass_diffusion.hheat_conduction.h, mass_diffusion.hheat_conduction.h에서 참조됩니다. 참조한 사람 man.cpp 성공적으로 컴파일된 후 링크할 때 오류가 보고되었습니다.LINK2005。我已经使用了#ifndef ... #define ... #endif이 방어 구문에는 파일 내부에 동일한 이름의 함수가 하나씩만 노출되어 있는데 왜 노출되지 않습니까? 외부에 오류가 보고되나요?

  2. 오류 메시지
    Visual studio 2017은 C++ 오류를 컴파일합니다. LNK2005 Mass_diffusion.obj "void __cdecl Compute(class std::Vector<struct user ,class std::allocator<struct user > > ,class std::Vector<struct item ,class std::allocator<struct item > )"이 heat_conduction.obj에 정의되었습니다.

  3. 관련 코드

    //common.h
    #ifndef _COMMON_H
    #define _COMMON_H
    ...
    struct user;
    struct item;
    struct 관계;
    ...
    typedef unsigned int _container_number_;
    typedef unsigned int _value_number_;
    . ..
    typedef std::벡터<user*> user_container;
    typedef std::벡터<item*> item_container;
    #endif // !_COMMON_H
    ...
    //mass_diffusion.h
    #include "common.h"
    extern void init_md(user_container, item_container);
    void Compute(user_container _ulist, item_container _ilist);
    ...
    //mass_diffusion.cpp
    #include "mass_diffusion.h"
    void init_md(user_container _ulist, item_container _ilist){...};
    void Compute(user_container _ulist, item_container _ilist) {...};
    ...
    //heat_conduction.h
    # "common.h".extern void init_hc (user_container
    _ulist, item_container _ilist); void compute (user_container
    _ulist, item_container _ilist); duction .h"void init_hc(user_container
    _ulist, item_container
    _ilist){...};void Compute(user_container _ulist, item_container
    _ilist) {...};
    ...//main. cpp
    #include "mass_diffusion.h"#include "heat_conduction.h"

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

모든 응답(1)
PHPzhong

원래 오류가 보고됩니다. 각 모듈이 동일한 파일에 연결되어 있으면 링커는 .h에 노출된 내용에 대해 신경 쓰지 않을 것입니다. 해결책은 각 모듈을 독립적으로 만드는 것입니다. so 또는 dll로 컴파일한 다음 호출하거나 네임스페이스를 사용하세요

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!