为 haskell 堆栈项目编写静态 cpp 库
Writing a static cpp library for a haskell stack project
我正在尝试为带有Haskell堆栈的Windows编写调试器。因为没有其他方法可以使用 haskell 包将正确的标志传递给CreateProcess
,所以我决定为它编写一个包装器。这是我所做的:
// process.h
#pragma once
// Headers
#include <Windows.h>
// Functions
HANDLE CreateDebuggedProcess(LPCSTR lpApplicationName);
和
//process.cpp
#include <Windows.h>
#include "process.h"
HANDLE CreateDebuggedProcess(LPCSTR lpApplicationName)
{
STARTUPINFO startup_info = { 0 };
PROCESS_INFORMATION process_information = { 0 };
startup_info.cb = sizeof(startup_info);
if (!CreateProcessA(
lpApplicationName,
NULL,
NULL,
NULL,
FALSE,
DEBUG_ONLY_THIS_PROCESS,
NULL,
NULL,
&startup_info,
&process_information
))
{
return INVALID_HANDLE_VALUE;
}
return process_information.hProcess;
}
我编译成DebuggedProcess.lib
在Haskell项目中,我有:
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import System.Win32.Types
import Foreign.C.String
main :: IO ()
main = do
withCString "cmd.exe" c_CreateDebuggedProcess
putStrLn "created process"
foreign import ccall "DebuggedProcess.lib CreateDebuggedProcess"
c_CreateDebuggedProcess :: LPCSTR -> IO HANDLE
我已将.lib
文件添加到堆栈路径(使用stack path --extra-include-dirs
验证(并添加了extra-libraries: [DebuggedProcess]
.
然而,我收到以下错误:
>stack build
Building all executables for `tape' once. After a successful build of all of them, only specified executables will be rebuilt.
tape-0.1.0.0: configure (lib + exe)
Configuring tape-0.1.0.0...
Cabal-simple_Z6RU0evB_2.2.0.1_ghc-8.4.3.exe: Missing dependencies on foreign
libraries:
* Missing (or bad) C libraries: DebuggedProcess, DebuggedProcess,
DebuggedProcess
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.If
the library files do exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
-- While building custom Setup.hs for package tape-0.1.0.0 using:
C:srsetup-exe-cachex86_64-windowsCabal-simple_Z6RU0evB_2.2.0.1_ghc-8.4.3.exe --builddir=.stack-workdist7d103d30 configure --with-ghc=C:UsersyotamAppDataLocalProgramsstackx86_64-windowsghc-8.4.3binghc.EXE --with-ghc-pkg=C:UsersyotamAppDataLocalProgramsstackx86_64-windowsghc-8.4.3binghc-pkg.EXE --user --package-db=clear --package-db=global --package-db=C:srsnapshots68fc3218pkgdb --package-db=D:tape.stack-workinstalldb7ce97cpkgdb --libdir=D:tape.stack-workinstalldb7ce97clib --bindir=D:tape.stack-workinstalldb7ce97cbin --datadir=D:tape.stack-workinstalldb7ce97cshare --libexecdir=D:tape.stack-workinstalldb7ce97clibexec --sysconfdir=D:tape.stack-workinstalldb7ce97cetc --docdir=D:tape.stack-workinstalldb7ce97cdoctape-0.1.0.0 --htmldir=D:tape.stack-workinstalldb7ce97cdoctape-0.1.0.0 --haddockdir=D:tape.stack-workinstalldb7ce97cdoctape-0.1.0.0 --dependency=Win32=Win32-2.6.1.0 --dependency=base=base-4.11.1.0 --extra-include-dirs=C:UsersyotamAppDataLocalProgramsstackx86_64-windowsmsys2-20180531mingw64include --extra-include-dirs=D:tapelib --extra-lib-dirs=C:UsersyotamAppDataLocalProgramsstackx86_64-windowsmsys2-20180531mingw64bin --extra-lib-dirs=C:UsersyotamAppDataLocalProgramsstackx86_64-windowsmsys2-20180531mingw64lib --enable-tests --enable-benchmarks
Process exited with code: ExitFailure 1
我对如何解决这个问题一无所知。任何帮助将不胜感激
只需在.cabal
文件中使用c-sources:
,即可使您的"库"静态编译成Haskell可执行文件。下面是示例:https://github.com/commercialhaskell/stack/pull/4238/files
相关文章:
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 不要使用静态强制转换进行算术转换(cpp-core-guidelines)
- 静态 CPP 中的非静态成员
- 为 haskell 堆栈项目编写静态 cpp 库
- LNK2019 在文件中调用静态成员的方法时出错.cpp
- 访问从 CPP 文件到其他头文件的静态变量
- 如何将 cpp 文件中的静态函数公开给其他文件
- 从 .so/.o 文件中获取 C/cpp 中的静态库列表
- 如何使用 PHP-CPP 在 PHP 类中添加静态数组
- C++文件中.cpp静态对象声明
- cpp 静态对象实例化
- 静态链接 ActiveMQ-cpp
- 在定义(.cpp文件)中初始化静态浮点 constexpr 成员是可能的
- 如何在标题和CPP之间拆分静态/模板类
- 在CPP中访问静态功能的指针
- 如果标头包含在另一个标头中,但不包含 CPP,则静态断言
- CMake - 将静态 yaml-cpp 作为 git 子模块的链接器错误
- 声明和修改结构的静态阵列-CPP
- Paho CPP - 编译为静态可执行文件
- 动态增长的向量,在 cpp 中声明为静态