0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【C++】clang++で.ixxをプリコンパイルする方法

Posted at

最初に結論

clang++のオプションを以下のように指定してコンパイルさせます。

# mod.ixxをC++モジュールとして扱い、mod.pcmとしてプリコンパイルする
clang++ -x c++-module mod.ixx --std=c++23 --precompile -o mod.pcm
# プリコンパイルしたmod.pcmとリンクさせて、main.cppをコンパイルする。
clang++ main.cpp -fuse-ld=lld --std=c++23 -fmodule-file=mod=mod.pcm mod.pcm -o main.exe

概要

通常、clang++のみでC++開発環境を完結できる場合、.cppmでモジュールファイルを作成します。しかし、何らかの理由で、Visual Studioの.ixxをプリコンパイルしたいケースがあると思います。

通常、clang++ mod.cppm --std=c++23 --precompile -o mod.pcmのように入力すると、clang++がmod.cppmを自動的にC++モジュールとして認識し、プリコンパイルしてくれます。しかし、mod.cppmmod.ixxという名前になると何故か認識してくれず、clang++: warning: mod.ixx: 'linker' input unused [-Wunused-command-line-argument]という警告が出力されて、mod.pcmが出力されません。
上述のようなオプションを指定することでプリコンパイルできるようになります。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?