xz Utilsの導入方法

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
ソーン

xz Utilsの導入方法

#1

投稿記事 by ソーン » 12年前

lzmaがパブリックドメインということで興味を持ち、xz utilsをダウンロード(*1)し、こちら(*2)を参考に試してみたのですが、リンクエラーが発生します。
なにかライブラリを含めなければいけないはずですが、どうすればいいのでしょうか。liblzma.aというのが怪しいのですが、使い方がわかりません。
環境: win7, VS2012, C++
*1 http://tukaani.org/xz/ の xz-5.0.5-windows.zip
*2 http://s-yata.jp/docs/xz-utils/

コード:

#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <assert.h>
#include "lzma.h"

int main()
{
	std::ifstream ifs("main.cpp");
	std::ofstream ofs("main.xz");
	lzma_stream strm = LZMA_STREAM_INIT;

	lzma_ret ret = lzma_easy_encoder(&strm, 6, LZMA_CHECK_CRC64);
	assert(ret == LZMA_OK);


	lzma_action action = LZMA_RUN;
	do {
		static uint8_t inbuf[32];
		static uint8_t outbuf[32];
		ifs.read((char*)inbuf, sizeof(inbuf));
		strm.next_in = inbuf;
		strm.avail_in = (size_t)ifs.gcount();
		if (ifs.eof()) {
			action = LZMA_FINISH;
		}
		do {
			strm.next_out = outbuf;
			strm.avail_out = _countof(outbuf);
			ret = lzma_code(&strm, action);
			assert((ret == LZMA_OK) || (ret == LZMA_STREAM_END));
			ofs.write((char*)outbuf, (char*)strm.next_out-(char*)outbuf);

		} while (strm.avail_out == 0);
		assert(strm.avail_in == 0);
	} while (action != LZMA_FINISH);
	assert(ret == LZMA_STREAM_END);

	return 0;
}
1>main.obj : error LNK2019: 未解決の外部シンボル __imp__lzma_code が関数 _main で参照されました。
1>main.obj : error LNK2019: 未解決の外部シンボル __imp__lzma_easy_encoder が関数 _main で参照されました。


P.S. IEだとコードが一行で表示されるのですが私だけでしょうか。火狐だと大丈夫なんですが...

ソーン

Re: xz Utilsの導入方法

#2

投稿記事 by ソーン » 12年前

半分ほど自己解決しました。
README-Windows.txtにlibファイルの作成方法が書いてありました。

To link against liblzma.dll, you need to create an import library
first. You need the "lib" command from MSVC and liblzma.def from
the "doc" directory of this package. Here is the command that works
on 32-bit x86:

lib /def:liblzma.def /out:liblzma.lib /machine:ix86

On x86-64, the /machine argument has to naturally be changed:

lib /def:liblzma.def /out:liblzma.lib /machine:x64

ここでx64を使った場合は変わらずリンクエラーとなり、ix86を使った場合はアプリケーションを正しく起動できませんでした(0xc000007b)と表示されます。(http://hpcgi2.nifty.com/natupaji/bbs/pa ... ew&no=2391)

よろしくお願いします。

アバター
h2so5
副管理人
記事: 2212
登録日時: 15年前
住所: 東京
連絡を取る:

Re: xz Utilsの導入方法

#3

投稿記事 by h2so5 » 12年前

状況がよくわかりません。
アプリケーションはx64でビルドしているのですか?
ix86を使った場合はリンクエラーは出ないのでしょうか。

ソーン

Re: xz Utilsの導入方法

#4

投稿記事 by ソーン » 12年前

ビルドは32bitで行っていますが、OSは64bitです。ごめんなさい書き忘れました。
ix84ではビルドは成功しますが、実行すると上記のエラーで実行できません。

アバター
へにっくす
記事: 634
登録日時: 13年前
住所: 東京都

Re: xz Utilsの導入方法

#5

投稿記事 by へにっくす » 12年前

ソーン さんが書きました:P.S. IEだとコードが一行で表示されるのですが私だけでしょうか。火狐だと大丈夫なんですが...
ここ参照。

http://dixq.net/forum/viewtopic.php?f=3&t=13306
written by へにっくす

閉鎖

“C言語何でも質問掲示板” へ戻る