我想知道如何在我创建的C++中使用静态库,首先是lib:
// header: foo.h
int foo(int a);
Run Code Online (Sandbox Code Playgroud)
.
// code: foo.cpp
#include foo.h
int foo(int a)
{
return a+1;
}
Run Code Online (Sandbox Code Playgroud)
然后我首先编译库:
现在我想在某些文件中使用这些库,如:
// prog.cpp
#include "foo.h"
int main()
{
int i = foo(2);
return i;
}
Run Code Online (Sandbox Code Playgroud)
我现在该如何编译?我做了:
g++ -L. -lfoo prog.cpp
Run Code Online (Sandbox Code Playgroud)
但是因为找不到函数foo而得到错误
我怎么能用writeFile写一个[String]呢?
我有 ["one", "two", "three"]
我想进入文件:
one two three
Run Code Online (Sandbox Code Playgroud)
如何用haskell做到这一点?如果需要,我可以写一个额外的功能.
谁可以给我一个简短的例子,我调用一些系统命令,然后用haskell读出来,例如打印出来?
我知道我可以使用System.Cmd来制作系统命令,如:nm,ls,mkdir等.
但我不需要只调用它们我需要读取它并使用readed字符串进行一些操作
我想打印一个字符串列表,如["hallo", "world", "!"]使用putStrLn,以便我得到输出:
hello
world
!
Run Code Online (Sandbox Code Playgroud)
如何使用函数执行此操作?我有
printMe :: [String] -> String
printMe (x:xs) =
Run Code Online (Sandbox Code Playgroud)
但不知道该怎么做
在哪里可以找到如何解析c ++头文件的好指令?
编辑:我想用haskell解析它,有一个parsec libraray但我需要一些例子.
怎么能帮助我让这个主要功能运行,不知道该怎么做,我做了一个小例子:
tuple :: String -> (Bool, String)
tuple x = (True, x)
getStr :: String
getStr = "test"
main = do
putStrLn snd (tuple getStr)
putStrLn "End"
Run Code Online (Sandbox Code Playgroud)