- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个正在尝试构建的 C 文件,但它给了我链接器错误。原因是它找不到其他源文件中定义的方法定义。
我在这里想要做的是定义这个源文件所定位的方法。 我给出的代码是我正在尝试构建的主程序。 任何建议都非常受欢迎,我们将不胜感激。
#include<stdio.h>
#include<jni.h>
#include<windows.h>
#include <stdbool.h>
#include "RunnerClass.h"
#include "unistd.h"
#include "apr_getopt.h"
#include "apr_portable.h"
#include "C:\JNItest\src\common\error_debug.h"
#include "C:\JNItest\src\common\event.h"
#include "C:\JNItest\src\common\context.h"
#include "C:\JNItest\src\common\alloc.h"
#include "C:\JNItest\src\core\nxlog.h"
#include "C:\JNItest\src\core\modules.h"
#include "C:\JNItest\src\core\router.h"
#include "C:\JNItest\src\core\ctx.h"
#include "C:\JNItest\src\core\core.h"
#define NX_LOGMODULE NX_LOGMODULE_CORE
static nxlog_t nxlog;
static apr_os_thread_t _nxlog_initializer = 0;
static void WINAPI nx_win32_svc_main(DWORD argc, LPTSTR * argv);
static void WINAPI nx_win32_svc_change(DWORD);
extern void nx_logger_disable_foreground();
static void print_usage();
static void set_configfile();
static bool do_install = FALSE;
static bool do_uninstall = FALSE;
static SERVICE_STATUS svc_status;
static SERVICE_STATUS_HANDLE *svc_status_handle = NULL;
JNIEXPORT void JNICALL Java_RunnerClass_parse_1cmd_1line
(JNIEnv * env, jobject jobj, jint argc, const jstring * const *argv){
char *opt_arg;
int rv;
apr_getopt_t *opt;
int ch;
static apr_getopt_option_t options[] = {
{ "help", 'h', 0, "print help" },
{ "foreground", 'f', 0, "run in foreground" },
{ "stop", 's', 0, "stop a running instance" },
// { "reload", 'r', 0, "reload configuration of a running instance" },
{ "conf", 'c', 1, "configuration file" },
{ "verify", 'v', 0, "verify configuration file syntax" },
{ "install", 'i', 0, "install service available to service manager" },
{ "uninstall", 'u', 0, "uninstall service" },
{ NULL, 0, 1, NULL },
};
apr_getopt_init(&opt, nxlog.pool, argc,(void *) argv);
while ( (rv = apr_getopt_long(opt, options, &ch,(void *) &opt_arg)) == APR_SUCCESS )
{
switch ( ch )
{
case 'c': /* configuration file */
nxlog.cfgfile = apr_pstrdup(nxlog.pool, opt_arg);
break;
case 'f': /* foreground */
nxlog.foreground = TRUE;
break;
case 'h': /* help */
print_usage();
exit(-1);
case 's': /* stop */
nxlog.do_stop = TRUE;
break;
/*
case 'r': // reload
nxlog.do_restart = true;
break;
*/
case 'v': /* verify */
nxlog.verify_conf = TRUE;
nxlog.ctx->ignoreerrors = FALSE;
break;
case 'i': /* install */
do_install = TRUE;
break;
case 'u': /* uninstall */
do_uninstall = TRUE;
break;
default:
print_usage();
exit(-1);
}
}
set_configfile();
if ( (rv != APR_SUCCESS) && (rv !=APR_EOF) )
{
throw(rv ,"Could not parse options");///////////
}
}
JNIEXPORT void JNICALL Java_RunnerClass_nx_1win32_1svc_1stop
(JNIEnv * env, jobject jobj){
SC_HANDLE service_manager = NULL;
SC_HANDLE service_handle = NULL;
SERVICE_STATUS status;
nx_exception_t e;
// Connect to service manager
service_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if ( service_manager == NULL )
{
nx_win32_error("Cannot initialize access to the service manager");
}
try
{
service_handle = OpenService(service_manager, "nxlog", SERVICE_ALL_ACCESS);
if ( service_handle == NULL )
{
nx_win32_error("Couldn't open nxlog service");
}
else
{
if ( QueryServiceStatus(service_handle, &status) )
{
if ( status.dwCurrentState != SERVICE_STOPPED )
{
log_info("Service currenty active - stopping service...");
if ( !ControlService(service_handle, SERVICE_CONTROL_STOP, &status) )
{
nx_win32_error("Couldn't stop service");
}
else
{
Sleep(500);
}
}
else
{
log_error("Service is already stopped");
}
}
// Close connection to service
CloseServiceHandle(service_handle);
}
// Close connection to service manager
CloseServiceHandle(service_manager);
}
catch(e)
{
if ( service_handle != NULL )
{
CloseServiceHandle(service_handle);
}
if ( service_manager != NULL )
{
CloseServiceHandle(service_manager);
}
rethrow(e);
}
}
JNIEXPORT void JNICALL Java_RunnerClass_nx_1win32_1svc_1install
(JNIEnv * env, jobject jobj){
SC_HANDLE service_manager;
SC_HANDLE new_service = NULL;
HKEY regkey;
uint32_t regtype = 0;
char regvalbuf[1024];
uint32_t regvalbufsize = 1024;
char servicename[1024];
// Connect to service manager
service_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if ( service_manager == NULL )
{
nx_win32_error("Cannot initialize access to the service manager");
}
//FIXME use nxlog.ctx.user to invoke service in CreateService
// default in case registry lookup would fail
apr_cpystrn(servicename,
"\"c:\\Program Files\\nxlog\\nxlog.exe\" -c \"c:\\Program Files\\nxlog\\nxlog.conf\"",
sizeof(servicename));
if ( RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\nxlog", ®key) == ERROR_SUCCESS )
{
if ( RegQueryValueEx(regkey, "installdir", 0,(void *) ®type,(unsigned char *) regvalbuf,(void *) ®valbufsize) == ERROR_SUCCESS )
{
if ( regtype == REG_SZ )
{
apr_snprintf(servicename, sizeof(servicename), "\"%snxlog.exe\"", regvalbuf);
}
}
RegCloseKey(regkey);
}
// Install the new service
new_service = CreateService(service_manager, "nxlog", "nxlog",
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START, SERVICE_ERROR_IGNORE,
servicename, NULL, NULL,
"eventlog\0", NULL, NULL);
if ( new_service == NULL )
{
nx_win32_error("Couldn't create service");
}
else
{
CloseServiceHandle(new_service);
log_info("Service successfully installed");
}
// Close the connection to service manager
CloseServiceHandle(service_manager);
}
JNIEXPORT void JNICALL Java_RunnerClass_nx_1win32_1svc_1uninstall
(JNIEnv * env, jobject jobj){
SC_HANDLE service_manager = NULL;
SC_HANDLE service_handle = NULL;
SERVICE_STATUS query_status;
nx_exception_t e;
// Connect to service manager
service_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if ( service_manager == NULL )
{
nx_win32_error("Cannot initialize access to the service manager");
}
try
{
// Connect to service
service_handle = OpenService(service_manager, "nxlog", SERVICE_ALL_ACCESS | DELETE);
if ( service_handle == NULL )
{
nx_win32_error("Couldn't open nxlog service");
}
else
{
// Check that the service is stopped
if ( QueryServiceStatus(service_handle, &query_status) &&
(query_status.dwCurrentState == SERVICE_RUNNING) )
{
throw_msg("Service is running, please stop it first.");
}
else
{ // we can remove
if ( DeleteService(service_handle) == FALSE )
{
nx_win32_error("Couldn't delete service");
}
else
{
log_info("Service successfully uninstalled");
}
}
// Close connection to service
CloseServiceHandle(service_handle);
}
// Close connection to service manager
CloseServiceHandle(service_manager);
}
catch(e)
{
if ( service_handle != NULL )
{
CloseServiceHandle(service_handle);
}
if ( service_manager != NULL )
{
CloseServiceHandle(service_manager);
}
rethrow(e);
}
}
JNIEXPORT void JNICALL Java_RunnerClass_nx_1win32_1svc_1main
(JNIEnv * env, jobject jobj, jint argc, jstring *argv){
nx_context_t thread_context;
nx_exception_t e;
if ( _nxlog_initializer == 0 )
{ // running from service manager
ASSERT(nx_init((void *)&argc, (void *)&argv, NULL) == TRUE);
nxlog_init(&nxlog);
nx_logger_disable_foreground();
}
else if ( _nxlog_initializer != apr_os_thread_current() )
{
// service dispatcher runs in a new thread, we need
// to initialize the exception context.
_nxlog_initializer = apr_os_thread_current();
memset(&thread_context, 0, sizeof(nx_context_t));
init_exception_context(&thread_context.exception_context);
apr_threadkey_private_set(&thread_context, nx_get_context_key());
}
log_debug("nx_win32_svc_main");
try
{
// read config cache
nx_config_cache_read();
log_debug("nxlog cache read");
// load DSO and read and verify module config
nx_ctx_config_modules(nxlog.ctx);
log_debug("nxlog config OK");
// initialize modules
nx_ctx_init_modules(nxlog.ctx);
// initialize log routes
nx_ctx_init_routes(nxlog.ctx);
nx_ctx_init_jobs(nxlog.ctx);
nx_ctx_restore_queues(nxlog.ctx);
// setup threadpool
nxlog_create_threads(&nxlog);
// start modules
nx_ctx_start_modules(nxlog.ctx);
if ( nxlog.foreground != TRUE )
{
// register to service manager
svc_status_handle = (void *)RegisterServiceCtrlHandler("nxlog", nx_win32_svc_change);
if ( svc_status_handle == 0 )
{
nx_win32_error("RegisterServiceCtrlHandler() failed, couldn't register the service control handler");
}
// Signal to svc manager that we are running
svc_status.dwWin32ExitCode = 0;
svc_status.dwServiceSpecificExitCode = 0;
svc_status.dwCheckPoint = 0;
svc_status.dwWaitHint = 0;
svc_status.dwServiceType = SERVICE_WIN32;
svc_status.dwCurrentState = SERVICE_RUNNING;
svc_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
if ( SetServiceStatus(*svc_status_handle, &svc_status) == FALSE )
{
nx_win32_error("Cannot send start service status update");
}
}
//log_info(PACKAGE"-"VERSION_STRING" started");
}
catch(e)
{
log_exception(e);
log_error("exiting...");
svc_status.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus(*svc_status_handle, &svc_status);
exit(e.code);
}
// mainloop
nxlog_mainloop(&nxlog, FALSE);
nxlog_shutdown(&nxlog);
if ( nxlog.foreground != TRUE )
{
// Signal back that we are stopped
svc_status.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus(*svc_status_handle, &svc_status);
}
nxlog_exit_function();
}
JNIEXPORT void JNICALL Java_RunnerClass_nx_1win32_1svc_1dispatch
(JNIEnv * env, jobject jobj){
static SERVICE_TABLE_ENTRY svc_dispatch_table[] =
{
{ "nxlog", NULL },
{ NULL, NULL }
};
if ( StartServiceCtrlDispatcher(svc_dispatch_table) == FALSE )
{
nx_win32_error("Cannot start service dispatcher");
}
}
JNIEXPORT void JNICALL Java_RunnerClass_nx_1win32_1svc_1start
(JNIEnv * env, jobject jobj, jint argc, jstring argv){
SC_HANDLE service_manager = NULL;
SC_HANDLE service_handle = NULL;
SERVICE_STATUS status;
nx_exception_t e;
// Connect to service manager
service_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if ( service_manager == NULL )
{
nx_win32_error("Cannot initialize access to the service manager");
}
try
{
service_handle = OpenService(service_manager, "nxlog", SERVICE_ALL_ACCESS);
if ( service_handle == NULL )
{
nx_win32_error("Couldn't open nxlog service");
}
else
{
if ( QueryServiceStatus(service_handle, &status) )
{
if ( status.dwCurrentState != SERVICE_RUNNING )
{
log_info("Service not running - starting service...");
if ( StartService(service_handle, argc,(void *) argv) == 0 )
{
nx_win32_error("Failed to start nxlog service");
}
}
else
{
log_error("Service is already running");
}
}
// Close connection to service
CloseServiceHandle(service_handle);
}
// Close connection to service manager
CloseServiceHandle(service_manager);
}
catch(e)
{
if ( service_handle != NULL )
{
CloseServiceHandle(service_handle);
}
if ( service_manager != NULL )
{
CloseServiceHandle(service_manager);
}
rethrow(e);
}
}
JNIEXPORT void JNICALL Java_RunnerClass_nxlog_1exit_1function
(JNIEnv * env, jobject jbobj){
static bool exited = FALSE;
if ( exited == TRUE )
{
return;
}
exited = TRUE;
if ( _nxlog_initializer == 0 )
{
return;
}
if ( nxlog.pid != (int) getpid() )
{
return;
}
nx_ctx_free(nxlog.ctx);
apr_pool_destroy(nxlog.pool);
apr_terminate();
}
/* Callback for service changes */
static void WINAPI nx_win32_svc_change(DWORD cmd)
{
// Only STOP command is handled
switch ( cmd )
{
case SERVICE_CONTROL_STOP:
log_warn("stopping nxlog service");
nxlog.terminate_request = TRUE;
// Wait until service stops
while ( svc_status.dwCurrentState != SERVICE_STOPPED )
{
Sleep(500);
}
break;
case SERVICE_CONTROL_INTERROGATE:
// ignore
log_debug("ignoring unsupported service change request: SERVICE_CONTROL_INTERROGATE");
break;
case SERVICE_CONTROL_PAUSE:
log_warn("ignoring unsupported service change request: SERVICE_CONTROL_PAUSE");
break;
case SERVICE_CONTROL_CONTINUE:
log_warn("ignoring unsupported service change request: SERVICE_CONTROL_CONTINUE");
break;
case SERVICE_CONTROL_PARAMCHANGE:
log_warn("ignoring unsupported service change request: SERVICE_CONTROL_PARAMCHANGE");
break;
case 200:
nxlog_dump_info();
break;
case 201:
{
nx_ctx_t *ctx;
log_info("got user control signal, switching to debug loglevel");
ctx = nx_ctx_get();
ctx->loglevel = NX_LOGLEVEL_DEBUG;
}
break;
default:
log_warn("ignoring unsupported service change request (%d)", cmd);
}
}
static void print_usage()
{
printf(/*PACKAGE*/ "-" /*ERSION_STRING*/ "\n"
" usage: "
" nxlog.exe [OPTIONS]\n"
" [-h] print help\n"
" [-f] run in foreground, otherwise try to start the nxlog service\n"
" [-c conffile] specify an alternate config file\n"
" [-i] install service available to service manager\n"
" [-u] uninstall service\n"
" [-s] stop running nxlog service\n"
" [-v] verify configuration file syntax\n"
);
// " [-r] reload configuration of a running instance\n"
}
static void set_configfile()
{
HKEY regkey;
uint32_t regtype = 0;
char regvalbuf[1024];
uint32_t regvalbufsize = 1024;
if ( nxlog.cfgfile != NULL )
{
return;
}
if ( RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\nxlog", ®key) == ERROR_SUCCESS )
{
if ( RegQueryValueEx(regkey, "installdir", 0, (void *)®type,
(unsigned char *) regvalbuf,(void *) ®valbufsize) == ERROR_SUCCESS )
{
if ( regtype == REG_SZ )
{
nxlog.cfgfile = apr_psprintf(nxlog.pool, "%sconf\\nxlog.conf", regvalbuf);
}
}
RegCloseKey(regkey);
}
if ( nxlog.cfgfile == NULL )
{
//nxlog.cfgfile = apr_pstrdup(nxlog.pool, NX_CONFIGFILE);
}
}
最佳答案
您收到的确切错误消息是什么???
根据内存,JNIEXPORT 不包含“extern "C"” - 因此,如果您的源文件是 C++,您的函数名称将被破坏(并且链接器将找不到它们)。
关于c++ - C 中的链接器错误 : undefined Reference to "method" c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14833719/
我想在 java 中声明一个对象,就像在 C++ 中指向指针的指针,让我给你看一个例子: //*** At the application startup //Initialize a setting
考虑这段代码, struct A {}; struct B { B(const A&) {} }; void f(B) { cout << "f()"<
我正在尝试将一个C程序翻译成Rust。。C程序具有以下结构(归结为MRE):。在一个函数中,我将执行以下指针魔术:。不,我的问题是:我将如何在铁锈中实现同样的目标?。到目前为止,我在《铁锈》中尝试过的
我目前正在尝试将一个C程序翻译成Rust。。C程序具有以下结构(归结为MRE):。在一个函数中,我将执行以下指针魔术:。不,我的问题是:我将如何在铁锈中实现同样的目标?。到目前为止,我在《铁锈》中尝试
这个问题在这里已经有了答案: Add managed DLL dependencied to unmanaged C++ project (1 个回答) 关闭 6 年前。 我有这样一个场景: 使用
这是一个常见问答的集合,这也是一个社区维基,所以每个人都被邀请参与维护它。。正则表达式正在遭受给我ZE代码类型的问题和没有解释的糟糕答案。此参考旨在提供指向质量问答的链接。。此参考适用于以下语言:PH
我正在尝试在方案中模拟堆栈。我正在使用 DrScheme 并选择语言 R5RS。我需要创建 pop、push 和 peek 的函数。但我无法弄清楚如何通过引用传递。我已经阅读了一些关于盒子的信息,但是
我陷入了这个错误。我将代码部署在生产服务器上,它在端口 80 上运行。当我尝试登录管理页面时。如图所示,它给了我 403 错误。 可能是什么原因?我的 Django 代码或 nginx 配置有问题吗?
这是一段简单的 C++ 代码: A foo(){ A a; // create a local A object return a; } void bar(const A & a_r){ }
我正在使用从 torrenteditor 获取的 php 脚本来创建 torrent 文件,但是当我使用指定的方法创建新的 torrent 文件时,torrent 文件被创建但我收到很多通知。,就像这
MySQL: REFERENCES vs FOREIGN KEY + REFERENCES 我认为 REFERENCES 是更冗长的 FOREIGN KEY REFERENCES 语法的某种速记语法。
我想使用基于另一个方法引用的方法引用。这有点难以解释,所以我给你举个例子: Person.java public class Person{ Person sibling; int a
Java/C# 语言律师喜欢说他们的语言通过值传递引用。这意味着“引用”是在调用函数时复制的对象指针。 同时,在 C++ 中(以及在 Perl 和 PHP 中更动态的形式),引用是某个其他名称(或动态
当我需要实现递归 lambda 时,通常我这样做: auto factorial = [](auto& self, int n) -> int { return n == 0 ? 1 : n
我目前正在研究 DDD ,需要一些启发。 我有两个实体 Temple TempleVariant Temple(听筒)包含基本信息(名称,描述等),并具有n个变体,它们具有技术描述(CAD绘图,尺寸,
在 Grails 中 belongsTo允许一个域类与另一个域类建立级联关系。使用belongsTo时有两种类型的关系:引用和无引用。 Reference 在拥有的对象上创建属性,而 No Refer
我正在使用 AWS 和 Django Rest Framework 开发 Web 应用程序。(Django:v1.8,DRF:v3) 我一直在为 POST 多部分表单请求获取 django.reque
我按照下面的定义公开了 WCF 端点, 当我在 .NET 3.5 中添加“服务引用”时,我们在代理中获得了以下类,这非常好: [Syst
我在玩 constexpr 引用时产生了这种感觉。但问题本身与 constexpr 无关,只是被它揭示。 我们知道有“指向const的指针”,也有“const指针”。顺便说一句,由于后者的使用比前者少
我有 2 种类型的 refences,它们中的每一种都可以正常工作。 我尝试使用每一个并在 project build 中得到相同的结果。 请向我解释 COM 引用和引用之间的区别。 谢谢你。 最佳答
我是一名优秀的程序员,十分优秀!