我正在编写一个API作为内核模块,为设备驱动程序提供各种功能.我在mycode.c中写了三个函数.然后我构建并加载了模块,然后将mycode.h复制到<kernel>/include/linux中.在设备驱动程序中,我有一个#include <linux/mycode.h>并调用这三个函数.但是当我构建驱动程序模块时,我得到三个链接器警告,说明这些函数是未定义的.
笔记:
很明显,函数正在正确导出,内核知道它们的位置和位置.那么为什么司机不能看到他们的定义呢?知道我错过了什么吗?
编辑:我在这里找到了一些相关的信息: http ://www.kernel.org/doc/Documentation/kbuild/modules.txt
有时,外部模块使用来自另一个外部模块的导出符号.kbuild需要完全了解所有符号,以避免吐出有关未定义符号的警告.这种情况存在三种解决方案.
注意:建议使用顶级kbuild文件的方法,但在某些情况下可能不切实际.
使用顶级kbuild文件如果你有两个模块,foo.ko和bar.ko,其中foo.ko需要来自bar.ko的符号,你可以使用一个通用的顶级kbuild文件,所以这两个模块都是用同一个编译的建立.请考虑以下目录布局:
Run Code Online (Sandbox Code Playgroud)./foo/ <= contains foo.ko ./bar/ <= contains bar.ko The top-level kbuild file would then look like: #./Kbuild (or ./Makefile): obj-y := foo/ bar/ And executing $ make -C $KDIR M=$PWD will then do the expected and compile both modules with full任何一个模块的符号知识.
使用额外的Module.symvers文件构建外部模块时,会生成Module.symvers文件,其中包含未在内核中定义的所有导出符号.要从bar.ko访问符号,请将module.symvers文件从bar.ko的编译复制到构建foo.ko的目录.在模块构建期间,kbuild将读取外部模块目录中的Module.symvers文件,并且在构建完成时,将创建一个新的Module.symvers文件,其中包含已定义的所有符号的总和,而不是内核的一部分.
使用"make"变量KBUILD_EXTRA_SYMBOLS如果从另一个模块复制Module.symvers是不切实际的,则可以在构建文件中将空格分隔的文件列表分配给KBUILD_EXTRA_SYMBOLS.这些文件将在其符号表初始化期间由modpost加载.
但是对于所有这三种解决方案,为了让任何驱动程序使用我的API,它必须创建一个新的Makefile或直接访问我的Module.symvers文件?这看起来有点不方便.我希望他们能够#include我的头文件并且好好去.不存在其他替代方案吗?
我有以下模型,我试图找到一个特定的对象DbSet:
public class UserSkill
{
[Key, Column(Order = 1)]
public int UserId { get; set; }
[Key, Column(Order = 2)]
[ForeignKey("Skill")]
public int SkillId { get; set; }
public virtual Skill Skill { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我试图找到一个特定的以下两种方式UserSkill对象(我传递DbSet的UserSkills通过ViewBag):
ViewBag.UserSkills.Find(new { WebSecurity.CurrentUserId, item.SkillId })
ViewBag.UserSkills.Find(new UserSkill(WebSecurity.CurrentUserId, item.SkillId))
Run Code Online (Sandbox Code Playgroud)
但在这两种情况下,我都会收到错误:
传递的主键值的数量必须与实体上定义的主键值的数量相匹配.
我错过了什么?在我看来,主键由两列组成,我正在为find函数提供构成主键的两个值.
这两个例子完成了同一件事。但是幕后的区别是什么?我了解功能组件与React.Component和React.PureComponent的对比,但是我无法找到有关的相关文档React.FunctionComponent。
React.FunctionComponent
const MyComponentA: React.FunctionComponent = (props) => {
return (
<p>I am a React.FunctionComponent</p>
);
};
Run Code Online (Sandbox Code Playgroud)
普通的JS函数组件:
const MyComponentB = (props) => {
return (
<p>I am a plain JS function component</p>
);
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用一些 React 组件创建一个 npm 包,我几乎将其用于所有项目。这是文件夹结构和文件内容:
我的组件.jsx
import React, { Component } from 'react';
class MyComponent extends Component {
render() {
return (
<p>Hello, world!</p>
);
}
}
export default MyComponent;
Run Code Online (Sandbox Code Playgroud)
索引.js
// eventually there will be more components imported/exported here
import MyComponent from './MyComponent.jsx';
exports.MyComponent = MyComponent;
Run Code Online (Sandbox Code Playgroud)
webpack.config.js
module.exports = {
entry: './src/index.js',
output: {
path: './dist',
filename: 'bundle.js'
},
// some loaders...
};
Run Code Online (Sandbox Code Playgroud)
包.json
{
"name": "my-library",
"files": [
"dist",
"src" …Run Code Online (Sandbox Code Playgroud) 我使用这个脚本构建时遇到了这个错误:
webpack --colors --progress --watch --config --jsx-loader webpack.config.js
Run Code Online (Sandbox Code Playgroud)
这是我的package.json文件:
{
"dependencies": {
"autoprefixer": "^6.0.3",
"node-libs-browser": "^0.5.3",
"object-assign": "4.0.1",
"underscore": "1.8.3",
"react": "0.14.7",
"react-dom": "0.14.7",
"react-router": "2.0.0",
"history": "^1.17.0",
"superagent": "^1.8.0",
"react-addons-css-transition-group": "0.14.7",
"react-bootstrap": "0.28.2",
"react-select": "^1.0.0-beta9",
"moment": "2.11.2",
"truncate": "2.0.0",
"superagent-promise-plugin": "2.1.0",
"rrule": "2.1.0"
},
"devDependencies": {
"babel-core": "^6.13.2",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.13.2",
"babel-preset-stage-0": "^6.5.0",
"babel-runtime": "^6.11.6",
"css-loader": "^0.23.1",
"eslint": "^3.2.2",
"eslint-config-defaults": "^9.0.0",
"eslint-loader": "^1.5.0",
"eslint-plugin-react": "^6.0.0",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"html-webpack-plugin": "^2.22.0",
"isparta-instrumenter-loader": "^1.0.1",
"jsx-loader": "0.13.2",
"less": "^2.3.1",
"less-loader": …Run Code Online (Sandbox Code Playgroud) 我有一个通用的存储库架构,如下所示:
存储库
public interface IRepository<T> where T: class
{
IList<T> Get(Func<T, bool> where);
}
public abstract class Repository<T> : IRepository<T> where T: class
{
private readonly DbSet<T> _entity;
protected Repository(ApplicationDbContext dbContext)
{
_entity = dbContext.Set<T>();
}
public IList<T> Get(Func<T, bool> where)
{
return _entity.Where(where).ToList();
}
}
Run Code Online (Sandbox Code Playgroud)
然后像这样创建具体的实现:
用户库
public class UserRepository : Repository<ApplicationUser>
{
public UserRepository(ApplicationDbContext dbContext) : base(dbContext) {}
// Can add any other methods I want that aren't included in IRepository
}
Run Code Online (Sandbox Code Playgroud)
我可能会有很多服务,所以与其将每个服务单独传递到控制器中,我想我会尝试传递一个可以为我生成存储库的工厂。
仓库工厂
public interface IRepositoryFactory
{ …Run Code Online (Sandbox Code Playgroud) 我已经安装了TypeScript并在基本的Express服务器上运行,但遇到了问题。
import bodyParser from 'body-parser';
import express, { Express } from 'express';
const app: Express = express();
app.use(bodyParser.json()); // Error 1
app.use(bodyParser.urlencoded({ extended: true })); // Error 2
Run Code Online (Sandbox Code Playgroud)
错误1是这样的:
类型“ NextHandleFunction”中缺少属性“ pop”。[2345]
因此bodyParser.json()返回a createServer.NextHandleFunction但没有该pop属性。NextHandleFunction定义如下@types/connect:
export type NextHandleFunction = (req: http.IncomingMessage, res: http.ServerResponse, next: NextFunction) => void;
Run Code Online (Sandbox Code Playgroud)
是的,不pop。但是,解决此问题我有什么选择?
错误2是这样的:
类型'NextHandleFunction'不能分配给类型'(string | RegExp)[]'。[2345]
在这里,bodyParser.urlencoded()还会返回一个createServer.NextHandleFunction,但这不是该类型app.use()正在寻找的。
同样,不确定我在这里的选择。
package.json
"dependencies": {
"@types/body-parser": "^1.17.0",
"@types/connect": "^3.4.32",
"@types/express": "^4.16.0",
"@types/express-serve-static-core": …Run Code Online (Sandbox Code Playgroud) 我正在努力实现这样的目标:
Child2Settings - 拥有所有 BaseSettings + Child2Settings
[...]
ChildNSettings - 拥有所有 BaseSettings + ChildNSettings
那么我会在我的控制器中有这个:
public class Child1Controller : Controller
{
public Child1Controller(Child1Settings settings)
{
// settings.BaseSetting and settings.Child1Setting should both be accessible here
}
}
Run Code Online (Sandbox Code Playgroud)
我试过这个:
public class BaseSettings
{
public string BaseSetting { get; set; }
}
public class Child1Settings : BaseSettings
{
public string Child1Setting { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
appsettings.json
{
"BaseSettings": {
"BaseSetting": "BaseSettingValue"
},
"Child1Settings": …Run Code Online (Sandbox Code Playgroud) 我试图将类型为React.Component(或React.FunctionComponent)的变量传递给Route,如下所示:
import React from 'react';
import { Route } from 'react-router-dom';
type PrivateRouteProps = {
component: React.Component | React.FunctionComponent;
isAuthenticated: boolean;
login: (...args: any[]) => any;
path: string;
};
const PrivateRoute: React.FunctionComponent<PrivateRouteProps> = ({
component: Component,
isAuthenticated,
login,
path,
...rest
}) => {
return (
<Route
path={path}
{...rest}
render={props => {
if (isAuthenticated) {
return <Component {...props} />;
} else {
login();
return null;
}
}}
/>
);
};
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
JSX元素类型“ Component”没有任何构造或调用签名。[2604]
我已经阅读了许多有关此问题的其他主题,但它们似乎都处理了针对特定组件实现的此错误。我不能更改有问题的组件或以不同的方式导入它(就像通常接受的答案一样),因为它可以是任何组件。
我正在使用TypeScript 3.1.6,Babel Core 7.1和React 16.6.3。
假设我有以下JToken:
@"{
""data"": [
{
""company"": {
""ID"": ""12345"",
""location"": ""Some Location""
},
""name"": ""Some Name""
}
]
}";
Run Code Online (Sandbox Code Playgroud)
我想将此标记传递给输出此JToken的FlattenToken函数:
@"{
""data"": [
{
""company_ID"": ""12345"",
""company_location"": ""Some Location"",
""name"": ""Some Name""
}
]}"
Run Code Online (Sandbox Code Playgroud)
这样做的原因是我可以使用扁平的JToken并将其反序列化为DataTable.
不过,我迷失在混乱的JObjects,JTokens,JProperties和其他JMadness中.我在这篇文章中看到了答案,这很有帮助,但我仍然没有做对.
这是我到目前为止所拥有的:
public static JToken FlattenToken(JToken token)
{
foreach (JToken topLevelItem in token["data"].Children())
{
foreach (JToken field in topLevelItem.Value<JToken>())
{
foreach (JProperty property in field.Value<JObject>().Properties())
{
field.AddAfterSelf(JObject.Parse(@"{""" + property.Name + "_" + property.Value));
}
field.Remove();
}
}
return token;
}
Run Code Online (Sandbox Code Playgroud)
通过外部foreach循环的第一次迭代,topLevelItem =
{ …Run Code Online (Sandbox Code Playgroud) 我设置了两种流类型:
type Form1Fields = {
fieldA
}
type Form2Fields = {
fieldZ
}
type FormFields = Form1Fields | Form2Fields
Run Code Online (Sandbox Code Playgroud)
然后我函数接受一个FormFields对象作为参数:
const myFunction = (fields: FormFields) => return fields.fieldA;
Run Code Online (Sandbox Code Playgroud)
这给了我错误Cannot get fields.fieldA because property fieldA is missing on Form2Fields。
我明白它在说什么。根据Flow 文档,“在调用接受联合类型的函数时,我们必须传入其中一种类型。但在我们的函数内部,我们需要处理所有可能的类型。”
所以在myFunction,我需要做一些类似的事情:
if (typeof fields === Form1Fields) { ... }
else { ... }
Run Code Online (Sandbox Code Playgroud)
我可以用像 那样的原始类型做到这一点number,但似乎我不能用 Flow 类型做到这一点。
有没有办法将对象与 Flow 类型进行比较,或者是否有不同的方法来解决这个问题?
我在尝试使用Update-Database时遇到了我的Table模型的一些问题,所以我决定删除该表并从头开始.为此,我通过Visual Studio的Server Explorer删除了表.但是现在当我尝试使用新版本的Table模型再次使用Update-Database时,我收到错误"无法找到对象"dbo.Table"因为它不存在或者您没有权限."
我该如何解决?我有模型,但我无法生成SQL表.
我有以下内容JToken:
{
"ID": "9dbefe3f5424d972e040007f010038f2"
}
Run Code Online (Sandbox Code Playgroud)
但每当我ToString()在JToken对象上运行以字符串形式获取底层JSON时,它返回:
\"ID\": \"9dbefe3f5424d972e040007f010038f2\"
Run Code Online (Sandbox Code Playgroud)
预计会撤消报价,但为什么要删除花括号呢?它是有效的JSON.这似乎只在某些情况下发生,因为我能够成功地运行ToString()并且在其他(更复杂)上保持花括号JTokens.
c# ×6
javascript ×6
reactjs ×4
asp.net ×2
asp.net-mvc ×2
json ×2
json.net ×2
npm ×2
typescript ×2
webpack ×2
.net ×1
.net-core ×1
asp.net-core ×1
babeljs ×1
c ×1
express ×1
flowtype ×1
jsx ×1
kernel ×1
module ×1
node.js ×1
sql ×1
symbol-table ×1