1

I have a simple C source file in a src directory in my project. My Build.PL contains the following lines:

c_source => ['src'],
extra_compiler_flags => ['-std=c99']

However, all this does is compile it to a .o file in the src directory corresponding to the C file. What I'd really like is to have it compiled and linked to form an executable, then put in my bin directory.

Is this possible and advisable with Module::Build?

4

1 回答 1

1

虽然 ikegami 说这不是做事的正确方法(我同意它可能不是......),但我最终还是使用对象cbuilder上的 getterModule::Build手动进行编译。只有一个 C 文件,我认为这是一个小罪,这让我继续前进!

my $b = $builder->cbuilder();

my $obj_file = $b->compile(
    source => 'src/myfile.c',
    extra_compiler_flags => ['-std=c99'],
    include_dirs => ['/my/path/zeromq-3.2.4/include']
);

my $lib_file = $b->link_executable(
    objects => $obj_file,
    extra_linker_flags => [
        '-lpthread',
        '-L/my/path/sw/zmq/lib/',
        '-lzmq'
    ],
    exe_file => 'my_file'
);
于 2013-11-21T22:21:36.660 回答