LoginSignup
1
0

More than 5 years have passed since last update.

C++ Builder 10.2 Tokyo > Error: 未解決の外部シンボル 'System::Win::Comobj::CoInitFlags' が...参照されています > 対処

Last updated at Posted at 2018-01-17
動作環境
RAD Studio 10.2 Tokyo Update 2

プロジェクトをビルド時に以下を含むエラーが出る。

[ilink32 エラー] Error: 未解決の外部シンボル 'System::Win::Comobj::CoInitFlags' が C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\19.0\LIB\WIN32\DEBUG\RTLE.LIB|syssupp から参照されています

エラーの発生手順

  1. ファイル > 新規作成 > その他 を選択
  2. C++ Builderプロジェクト > コンソールアプリケーション を選択
  3. 「新規コンソールアプリケーション」ダイアログにて「ターゲットフレームワーク」は「なし」を選択
    • >> 以下のひな型ができる。
File1.cpp
#pragma hdrstop
#pragma argsused

#ifdef _WIN32
#include <tchar.h>
#else
  typedef char _TCHAR;
  #define _tmain main
#endif

#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

以下のように書き換える。

File1.cpp
#include <vcl.h>
#include <windows.h>

#pragma hdrstop
#pragma argsused

#ifdef _WIN32
#include <tchar.h>
#else
  typedef char _TCHAR;
  #define _tmain main
#endif

int _tmain(int argc, _TCHAR* argv[])
{
    String lpath = L"TEST";
    return 0;
}
  • ファイルをビルド: 成功
  • プロジェクトをビルド: 下記のエラーが出る

[ilink32 エラー] Error: 未解決の外部シンボル 'fastcall System::Internal::Strhlpr::UnicodeFree(System::UnicodeString&)' が C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\19.0\LIB\WIN32\DEBUG\VCLE.LIB|ustring から参照されています
[ilink32 エラー] Error: 未解決の外部シンボル '
fastcall System::Internal::Strhlpr::UnicodeSetLength(System::UnicodeString&, int)' が C:\PROGRAM FILES (X86)\EMBARCADERO\STUDIO\19.0\LIB\WIN32\DEBUG\VCLE.LIB|ustring から参照されています
[ilink32 エラー] Error: リンクを実行できません
失敗

対処

コンソールアプリケーションを新規作成する時にターゲットフレームワークを「ビジュアルコンポーネントライブラリ」にする。

qiita.png

作成されたひな型に対して以下のように書き換える。

File1.cpp
#include <vcl.h>
#include <windows.h>

#pragma hdrstop
#pragma argsused

#include <tchar.h>

#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
    String lpath = L"TEST";
    return 0;
}
  • ファイルをビルド: 成功
  • プロジェクトをビルド: 成功

Bugなのか仕様なのか

ターゲットフレームワークの選択により、File1.cpp以外の部分で何かが違うのだろう。

ビルドエラーのメッセージを見ただけでは上記の対処にたどり着けないだろう。

落とし穴

「新規コンソールアプリケーション」ダイアログにて「ターゲットフレームワーク」
はIDEインストール直後は「なし」になっている。

いったん「ビジュアルコンポーネントライブラリ」に変更すると、その変更が以後記憶される。

最初の状態とは違う設定をしている場合、環境を再構築した時にエラーが発生するようになり、その原因特定に時間を取られる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0