lein repl and any command with "lein" Doesn't Work - clojure
I have just started learning Clojure from Daniel Higginbottam's book called Clojure for the Brave and True. Needless to say, you need Leiningen and Cider for a good Clojure workflow.
Before I have tried installing cider to emacs, my Leiningen was working fine but somehow after I have tingled some settings with emacs (installing cider), my Leiningen installation started to give stack trace errors such as below: (I don't know how can this happen at all)
How can I fix this?
(Also, I have tried re-installing Leiningen, which didn't solve the issue.)
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
clojure.lang.Compiler$CompilerException: Syntax error compiling at (cider/nrepl.clj:1:1).
#:clojure.error{:phase :compile-syntax-check, :line 1, :column 1, :source "cider/nrepl.clj"}
at clojure.lang.Compiler.load (Compiler.java:7648)
clojure.lang.RT.loadResourceScript (RT.java:381)
clojure.lang.RT.loadResourceScript (RT.java:372)
clojure.lang.RT.load (RT.java:459)
clojure.lang.RT.load (RT.java:424)
clojure.core$load$fn__6839.invoke (core.clj:6126)
clojure.core$load.invokeStatic (core.clj:6125)
clojure.core$load.doInvoke (core.clj:6109)
clojure.lang.RestFn.invoke (RestFn.java:408)
clojure.core$load_one.invokeStatic (core.clj:5908)
clojure.core$load_one.invoke (core.clj:5903)
clojure.core$load_lib$fn__6780.invoke (core.clj:5948)
clojure.core$load_lib.invokeStatic (core.clj:5947)
clojure.core$load_lib.doInvoke (core.clj:5928)
clojure.lang.RestFn.applyTo (RestFn.java:142)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$load_libs.invokeStatic (core.clj:5985)
clojure.core$load_libs.doInvoke (core.clj:5969)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$require.invokeStatic (core.clj:6007)
clojure.core$require.doInvoke (core.clj:6007)
clojure.lang.RestFn.invoke (RestFn.java:421)
cider_nrepl.plugin$eval659$loading__6721__auto____660.invoke (plugin.clj:1)
cider_nrepl.plugin$eval659.invokeStatic (plugin.clj:1)
cider_nrepl.plugin$eval659.invoke (plugin.clj:1)
clojure.lang.Compiler.eval (Compiler.java:7177)
clojure.lang.Compiler.eval (Compiler.java:7166)
clojure.lang.Compiler.load (Compiler.java:7636)
clojure.lang.RT.loadResourceScript (RT.java:381)
clojure.lang.RT.loadResourceScript (RT.java:372)
clojure.lang.RT.load (RT.java:459)
clojure.lang.RT.load (RT.java:424)
clojure.core$load$fn__6839.invoke (core.clj:6126)
clojure.core$load.invokeStatic (core.clj:6125)
clojure.core$load.doInvoke (core.clj:6109)
clojure.lang.RestFn.invoke (RestFn.java:408)
clojure.core$load_one.invokeStatic (core.clj:5908)
clojure.core$load_one.invoke (core.clj:5903)
clojure.core$load_lib$fn__6780.invoke (core.clj:5948)
clojure.core$load_lib.invokeStatic (core.clj:5947)
clojure.core$load_lib.doInvoke (core.clj:5928)
clojure.lang.RestFn.applyTo (RestFn.java:142)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$load_libs.invokeStatic (core.clj:5985)
clojure.core$load_libs.doInvoke (core.clj:5969)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$require.invokeStatic (core.clj:6007)
clojure.core$require.doInvoke (core.clj:6007)
clojure.lang.RestFn.invoke (RestFn.java:408)
leiningen.core.utils$require_resolve.invokeStatic (utils.clj:102)
leiningen.core.utils$require_resolve.invoke (utils.clj:95)
leiningen.core.project$apply_middleware.invokeStatic (project.clj:850)
leiningen.core.project$apply_middleware.invoke (project.clj:843)
clojure.lang.ArrayChunk.reduce (ArrayChunk.java:58)
clojure.core.protocols$fn__8154.invokeStatic (protocols.clj:136)
clojure.core.protocols/fn (protocols.clj:124)
clojure.core.protocols$fn__8114$G__8109__8123.invoke (protocols.clj:19)
clojure.core.protocols$seq_reduce.invokeStatic (protocols.clj:31)
clojure.core.protocols$fn__8146.invokeStatic (protocols.clj:75)
clojure.core.protocols/fn (protocols.clj:75)
clojure.core.protocols$fn__8088$G__8083__8101.invoke (protocols.clj:13)
clojure.core$reduce.invokeStatic (core.clj:6828)
clojure.core$reduce.invoke (core.clj:6810)
leiningen.core.project$apply_middleware.invokeStatic (project.clj:845)
leiningen.core.project$apply_middleware.invoke (project.clj:843)
leiningen.core.project$activate_middleware.invokeStatic (project.clj:877)
leiningen.core.project$activate_middleware.invoke (project.clj:873)
leiningen.core.project$set_profiles.invokeStatic (project.clj:966)
leiningen.core.project$set_profiles.doInvoke (project.clj:959)
clojure.lang.RestFn.invoke (RestFn.java:425)
leiningen.core.project$init_project.invokeStatic (project.clj:1041)
leiningen.core.project$init_project.invoke (project.clj:1016)
leiningen.core.project$init_project.invokeStatic (project.clj:1042)
leiningen.core.project$init_project.invoke (project.clj:1016)
leiningen.core.main$default_project.invokeStatic (main.clj:419)
leiningen.core.main$default_project.invoke (main.clj:412)
leiningen.core.main$_main$fn__7419.invoke (main.clj:449)
leiningen.core.main$_main.invokeStatic (main.clj:442)
leiningen.core.main$_main.doInvoke (main.clj:439)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.lang.Var.applyTo (Var.java:705)
clojure.core$apply.invokeStatic (core.clj:665)
clojure.main$main_opt.invokeStatic (main.clj:514)
clojure.main$main_opt.invoke (main.clj:510)
clojure.main$main.invokeStatic (main.clj:664)
clojure.main$main.doInvoke (main.clj:616)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.lang.Var.applyTo (Var.java:705)
clojure.main.main (main.java:40)
Caused by: java.io.FileNotFoundException: Could not locate clojure/tools/nrepl/server__init.class, clojure/tools/nrepl/server.clj or clojure/tools/nrepl/server.cljc on classpath.
at clojure.lang.RT.load (RT.java:462)
clojure.lang.RT.load (RT.java:424)
clojure.core$load$fn__6839.invoke (core.clj:6126)
clojure.core$load.invokeStatic (core.clj:6125)
clojure.core$load.doInvoke (core.clj:6109)
clojure.lang.RestFn.invoke (RestFn.java:408)
clojure.core$load_one.invokeStatic (core.clj:5908)
clojure.core$load_one.invoke (core.clj:5903)
clojure.core$load_lib$fn__6780.invoke (core.clj:5948)
clojure.core$load_lib.invokeStatic (core.clj:5947)
clojure.core$load_lib.doInvoke (core.clj:5928)
clojure.lang.RestFn.applyTo (RestFn.java:142)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$load_libs.invokeStatic (core.clj:5985)
clojure.core$load_libs.doInvoke (core.clj:5969)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$require.invokeStatic (core.clj:6007)
clojure.core$require.doInvoke (core.clj:6007)
clojure.lang.RestFn.invoke (RestFn.java:1289)
cider.nrepl$eval665$loading__6721__auto____666.invoke (nrepl.clj:1)
cider.nrepl$eval665.invokeStatic (nrepl.clj:1)
cider.nrepl$eval665.invoke (nrepl.clj:1)
clojure.lang.Compiler.eval (Compiler.java:7177)
clojure.lang.Compiler.eval (Compiler.java:7166)
clojure.lang.Compiler.load (Compiler.java:7636)
clojure.lang.RT.loadResourceScript (RT.java:381)
clojure.lang.RT.loadResourceScript (RT.java:372)
clojure.lang.RT.load (RT.java:459)
clojure.lang.RT.load (RT.java:424)
clojure.core$load$fn__6839.invoke (core.clj:6126)
clojure.core$load.invokeStatic (core.clj:6125)
clojure.core$load.doInvoke (core.clj:6109)
clojure.lang.RestFn.invoke (RestFn.java:408)
clojure.core$load_one.invokeStatic (core.clj:5908)
clojure.core$load_one.invoke (core.clj:5903)
clojure.core$load_lib$fn__6780.invoke (core.clj:5948)
clojure.core$load_lib.invokeStatic (core.clj:5947)
clojure.core$load_lib.doInvoke (core.clj:5928)
clojure.lang.RestFn.applyTo (RestFn.java:142)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$load_libs.invokeStatic (core.clj:5985)
clojure.core$load_libs.doInvoke (core.clj:5969)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$require.invokeStatic (core.clj:6007)
clojure.core$require.doInvoke (core.clj:6007)
clojure.lang.RestFn.invoke (RestFn.java:421)
cider_nrepl.plugin$eval659$loading__6721__auto____660.invoke (plugin.clj:1)
cider_nrepl.plugin$eval659.invokeStatic (plugin.clj:1)
cider_nrepl.plugin$eval659.invoke (plugin.clj:1)
clojure.lang.Compiler.eval (Compiler.java:7177)
clojure.lang.Compiler.eval (Compiler.java:7166)
clojure.lang.Compiler.load (Compiler.java:7636)
clojure.lang.RT.loadResourceScript (RT.java:381)
clojure.lang.RT.loadResourceScript (RT.java:372)
clojure.lang.RT.load (RT.java:459)
clojure.lang.RT.load (RT.java:424)
clojure.core$load$fn__6839.invoke (core.clj:6126)
clojure.core$load.invokeStatic (core.clj:6125)
clojure.core$load.doInvoke (core.clj:6109)
clojure.lang.RestFn.invoke (RestFn.java:408)
clojure.core$load_one.invokeStatic (core.clj:5908)
clojure.core$load_one.invoke (core.clj:5903)
clojure.core$load_lib$fn__6780.invoke (core.clj:5948)
clojure.core$load_lib.invokeStatic (core.clj:5947)
clojure.core$load_lib.doInvoke (core.clj:5928)
clojure.lang.RestFn.applyTo (RestFn.java:142)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$load_libs.invokeStatic (core.clj:5985)
clojure.core$load_libs.doInvoke (core.clj:5969)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$require.invokeStatic (core.clj:6007)
clojure.core$require.doInvoke (core.clj:6007)
clojure.lang.RestFn.invoke (RestFn.java:408)
leiningen.core.utils$require_resolve.invokeStatic (utils.clj:102)
leiningen.core.utils$require_resolve.invoke (utils.clj:95)
leiningen.core.project$apply_middleware.invokeStatic (project.clj:850)
leiningen.core.project$apply_middleware.invoke (project.clj:843)
clojure.lang.ArrayChunk.reduce (ArrayChunk.java:58)
clojure.core.protocols$fn__8154.invokeStatic (protocols.clj:136)
clojure.core.protocols/fn (protocols.clj:124)
clojure.core.protocols$fn__8114$G__8109__8123.invoke (protocols.clj:19)
clojure.core.protocols$seq_reduce.invokeStatic (protocols.clj:31)
clojure.core.protocols$fn__8146.invokeStatic (protocols.clj:75)
clojure.core.protocols/fn (protocols.clj:75)
clojure.core.protocols$fn__8088$G__8083__8101.invoke (protocols.clj:13)
clojure.core$reduce.invokeStatic (core.clj:6828)
clojure.core$reduce.invoke (core.clj:6810)
leiningen.core.project$apply_middleware.invokeStatic (project.clj:845)
leiningen.core.project$apply_middleware.invoke (project.clj:843)
leiningen.core.project$activate_middleware.invokeStatic (project.clj:877)
leiningen.core.project$activate_middleware.invoke (project.clj:873)
leiningen.core.project$set_profiles.invokeStatic (project.clj:966)
leiningen.core.project$set_profiles.doInvoke (project.clj:959)
clojure.lang.RestFn.invoke (RestFn.java:425)
leiningen.core.project$init_project.invokeStatic (project.clj:1041)
leiningen.core.project$init_project.invoke (project.clj:1016)
leiningen.core.project$init_project.invokeStatic (project.clj:1042)
leiningen.core.project$init_project.invoke (project.clj:1016)
leiningen.core.main$default_project.invokeStatic (main.clj:419)
leiningen.core.main$default_project.invoke (main.clj:412)
leiningen.core.main$_main$fn__7419.invoke (main.clj:449)
leiningen.core.main$_main.invokeStatic (main.clj:442)
leiningen.core.main$_main.doInvoke (main.clj:439)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.lang.Var.applyTo (Var.java:705)
clojure.core$apply.invokeStatic (core.clj:665)
clojure.main$main_opt.invokeStatic (main.clj:514)
clojure.main$main_opt.invoke (main.clj:510)
clojure.main$main.invokeStatic (main.clj:664)
clojure.main$main.doInvoke (main.clj:616)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.lang.Var.applyTo (Var.java:705)
clojure.main.main (main.java:40)
Related
realtime v4l2src for deepstream test1 c application does not work
So my pipeline is as such which works with gst_parse_launch in the c code below but I wanted to use dynamic pipelines, and I am not getting error but at the same time, I am not getting the desired output too. gst-launch-1.0 v4l2src ! 'video/x-raw,format=(string)YUY2' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=(string)NV12' ! nvvidconv ! 'video/x-raw,format=(string)NV12' ! nvvideoconvert ! 'video/x-raw(memory:NVMM),format=(string)NV12' ! mux.sink_0 nvstreammux live-source=1 name=mux batch-size=1 width=640 height=480 ! nvinfer config-file-path=/opt/nvidia/deepstream/deepstream-4.0/sources/apps/sample_apps/deepstream-test1/dstest1_pgie_config.txt batch-size=1 ! nvmultistreamtiler rows=1 columns=1 width=640 height=480 ! nvvideoconvert ! nvdsosd ! nvegltransform ! nveglglessink and it runs perfectly with gst_parse_launch such as this c application #include <gst/gst.h> int main (int argc, char *argv[]) { GstElement *pipeline; GstBus *bus; GstMessage *msg; /* Initialize GStreamer */ gst_init (&argc, &argv); /* Build the pipeline */ pipeline = gst_parse_launch ("v4l2src ! video/x-raw,format=(string)YUY2 ! nvvidconv ! video/x-raw(memory:NVMM),format=(string)NV12 ! nvvidconv ! video/x-raw,format=(string)NV12 ! nvvideoconvert ! video/x-raw(memory:NVMM),format=(string)NV12 ! mux.sink_0 nvstreammux live-source=1 name=mux batch-size=1 width=640 height=480 ! nvinfer config-file-path=/opt/nvidia/deepstream/deepstream-4.0/sources/apps/sample_apps/deepstream-test1/dstest1_pgie_config.txt batch-size=1 ! nvmultistreamtiler rows=1 columns=1 width=640 height=480 ! nvvideoconvert ! nvdsosd ! nvegltransform ! nveglglessink", NULL); /* Start playing */ gst_element_set_state (pipeline, GST_STATE_PLAYING); /* Wait until error or EOS */ bus = gst_element_get_bus (pipeline); msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); /* Free resources */ if (msg != NULL) gst_message_unref (msg); gst_object_unref (bus); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); return 0; } But I am trying to make it run using this c application #include <gst/gst.h> typedef struct _CustomData{ GstElement *pipeline; GstElement *source; GstElement *filter1; GstElement *filter2; GstElement *filter3; GstElement *filter4; GstElement *convert1; GstElement *convert2; GstElement *mux; GstElement *infer; GstElement *tiler; GstElement *videoconvert1; GstElement *videoconvert2; GstElement *osd; GstElement *transform; GstElement *sink; GstElement *bin; }CustomData; static gboolean bus_call (GstBus * bus, GstMessage * msg, gpointer data) { GMainLoop *loop = (GMainLoop *) data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_EOS: g_print ("End of stream\n"); g_main_loop_quit (loop); break; case GST_MESSAGE_ERROR:{ gchar *debug; GError *error; gst_message_parse_error (msg, &error, &debug); g_printerr ("ERROR from element %s: %s\n", GST_OBJECT_NAME (msg->src), error->message); if (debug) g_printerr ("Error details: %s\n", debug); g_free (debug); g_error_free (error); g_main_loop_quit (loop); break; } default: break; } return TRUE; } int main(int argc, char *argv[]) { GMainLoop *loop = NULL; CustomData data; GstBus *bus; GstCaps *caps1, *caps2, *caps3, *caps4; gchar *string1 = "video/x-raw(memory:NVMM),format=(string)NV12"; guint bus_watch_id; gchar *path = "/opt/nvidia/deepstream/deepstream-4.0/sources/apps/sample_apps/deepstream-test1/dstest1_pgie_config.txt"; gst_init(&argc, &argv); loop = g_main_loop_new(NULL,FALSE); //create gstreamer elements data.pipeline = gst_pipeline_new("test_pipeline"); data.source = gst_element_factory_make("v4l2src", "source"); data.filter1 = gst_element_factory_make("capsfilter", "filter1"); data.filter2 = gst_element_factory_make("capsfilter", "filter2"); data.filter3 = gst_element_factory_make("capsfilter", "filter3"); data.filter4 = gst_element_factory_make("capsfilter", "filter4"); data.convert1 = gst_element_factory_make("nvvidconv","convert1"); data.convert2 = gst_element_factory_make("nvvidconv", "convert2"); data.videoconvert1 = gst_element_factory_make("nvvideoconvert", "videoconvert"); gst_bin_add_many(GST_BIN(data.bin), data.source, data.filter1, data.convert1, data.filter2, data.convert2, data.filter3, data.videoconvert1, data.filter4,NULL ); gst_element_link_many(data.source,data.filter1, data.convert1,data.filter2,data.convert2, data.filter3,data.videoconvert1, data.filter4, NULL); caps1 = gst_caps_new_simple("video/x-raw","format", G_TYPE_STRING,"YUY2", NULL ); caps2 = gst_caps_from_string(string1); caps3 = gst_caps_new_simple("video/x-raw","format", G_TYPE_STRING, "NV12",NULL); caps4 = gst_caps_from_string(string1); g_object_set(G_OBJECT(data.source), "device", "/dev/video0",NULL); g_object_set(G_OBJECT(data.filter1), "caps", caps1, NULL); g_object_set(G_OBJECT(data.filter2), "caps", caps2, NULL); g_object_set(G_OBJECT(data.filter3), "caps", caps3, NULL); g_object_set(G_OBJECT(data.filter4), "caps", caps4, NULL); data.mux = gst_element_factory_make("nvstreammux", "stream-muxer"); gst_bin_add(GST_BIN(data.pipeline), data.mux); gst_bin_add(GST_BIN(data.pipeline), GST_BIN(data.bin)); GstPad *sink_pad = gst_element_get_request_pad(data.mux, "sink_0"); GstPad *src_pad = gst_element_get_static_pad(data.bin, "src"); gst_pad_link(src_pad, sink_pad); gst_object_unref(sink_pad); gst_object_unref(src_pad); data.infer = gst_element_factory_make("nvinfer", "primary-nvinference-engine"); data.tiler = gst_element_factory_make("nvmultistreamtiler", "nvtiler"); data.videoconvert2 = gst_element_factory_make("nvvideoconvert", "video-convert2"); data.osd = gst_element_factory_make("nvdsosd", "nv-onscreendisplay"); data.transform = gst_element_factory_make("nvegltransform", "nvegl-transform"); data.sink = gst_element_factory_make("nveglglessink", "nvvideo-renderer"); gst_bin_add_many(GST_BIN(data.pipeline), data.mux, data.infer,data.tiler, data.videoconvert2, data.osd, data.transform,data.sink, NULL ); gst_element_link_many(data.mux, data.infer,data.tiler, data.videoconvert2, data.osd, data.transform,data.sink, NULL); g_object_set(G_OBJECT(data.mux), "live-source", 1, "name", "mux", "batch-size", 1, "width", 640, "height", 480, NULL); g_object_set(G_OBJECT(data.infer), "config-file-path",path, NULL); g_object_set(G_OBJECT(data.infer), "batch-size", 1); g_object_set(G_OBJECT(data.tiler), "rows", 1, "columns", 1, "width", 640, "height", 480, NULL); gst_element_set_state(data.pipeline,GST_STATE_PLAYING); g_print("Running\n"); /* we add a message handler */ bus = gst_pipeline_get_bus (GST_PIPELINE (data.pipeline)); bus_watch_id = gst_bus_add_watch (bus, bus_call, loop); gst_object_unref (bus); g_main_loop_run(loop); /* Out of the main loop, clean up nicely */ g_print ("Returned, stopping playback\n"); gst_element_set_state (data.pipeline, GST_STATE_NULL); g_print ("Deleting pipeline\n"); gst_object_unref (GST_OBJECT (data.pipeline)); g_source_remove (bus_watch_id); g_main_loop_unref (loop); return 0; } and it doesn't show the display anymore. What am I missing? oh and I am also getting this error five:18933): GLib-GObject-WARNING **: 12:27:23.209: cannot register existing type 'GstInterpolationMethod' (five:18933): GLib-GObject-CRITICAL **: 12:27:23.209: g_param_spec_enum: assertion 'G_TYPE_IS_ENUM (enum_type)' failed (five:18933): GLib-GObject-CRITICAL **: 12:27:23.209: validate_pspec_to_install: assertion 'G_IS_PARAM_SPEC (pspec)' failed (five:18933): GStreamer-CRITICAL **: 12:27:23.209: gst_bin_add_many: assertion 'GST_IS_BIN (bin)' failed (five:18933): GStreamer-CRITICAL **: 12:27:23.216: gst_bin_add: assertion 'GST_IS_ELEMENT (element)' failed (five:18933): GStreamer-CRITICAL **: 12:27:23.217: gst_element_get_static_pad: assertion 'GST_IS_ELEMENT (element)' failed (five:18933): GStreamer-CRITICAL **: 12:27:23.217: gst_pad_link_full: assertion 'GST_IS_PAD (srcpad)' failed (five:18933): GStreamer-CRITICAL **: 12:27:23.217: gst_object_unref: assertion 'object != NULL' failed (five:18933): GStreamer-WARNING **: 12:27:23.263: Name 'stream-muxer' is not unique in bin 'test_pipeline', not adding (five:18933): GLib-GObject-WARNING **: 12:27:23.266: g_object_set_is_valid_property: object class 'GstNvInfer' has no property named '\x90\xa1J\x8fU' Using winsys: x11 Creating LL OSD context new 0:00:00.759463907 18933 0x558f53f760 INFO nvinfer gstnvinfer.cpp:519:gst_nvinfer_logger:<primary-nvinference-engine> NvDsInferContext[UID 1]:initialize(): Trying to create engine from model files 0:00:27.684391089 18933 0x558f53f760 INFO nvinfer gstnvinfer.cpp:519:gst_nvinfer_logger:<primary-nvinference-engine> NvDsInferContext[UID 1]:generateTRTModel(): Storing the serialized cuda engine to file at /opt/nvidia/deepstream/deepstream-4.0/samples/models/Primary_Detector/resnet10.caffemodel_b1_int8.engine Running EDIT: I think it has something to do with the nvvidconv or nvvideoconvert not linking with nvstreammux properly.I was testing with this c application.. #include <gst/gst.h> int main(int argc, char* argv[]) { GstElement *pipeline, *source, *filter1, *filter2, *convert1, *convert2, *filter3, *convert3, *filter4, *convert4, *sink, *mux, *infer; GstCaps *caps1, *caps2,*caps3, *caps4; gchar* string1 = "video/x-raw(memory:NVMM),format=(string)NV12"; GstBus *bus; GstMessage *msg; GstStateChangeReturn ret; gst_init(&argc, &argv); pipeline = gst_pipeline_new("test_pipeline"); source = gst_element_factory_make("v4l2src", "source"); filter1 = gst_element_factory_make("capsfilter", "filter1"); filter2 = gst_element_factory_make("capsfilter", "filter2"); filter3 = gst_element_factory_make("capsfilter", "filter3"); filter4 = gst_element_factory_make("capsfilter", "filter4"); convert3 = gst_element_factory_make("nvvidconv","convert3"); convert1 = gst_element_factory_make("nvvidconv", "convert1"); convert2 = gst_element_factory_make("nvvidconv", "convert2"); convert4 = gst_element_factory_make("nvvideoconvert", "convert4"); infer = gst_element_factory_make("nvinfer", "inference"); sink = gst_element_factory_make("autovideosink", "sink"); mux = gst_element_factory_make("nvstreammux", "nv-stream-muxer"); caps1 = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "YUY2",NULL); caps2 = gst_caps_from_string(string1); caps3 = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "NV12", NULL); caps4 = gst_caps_from_string(string1); g_object_set(G_OBJECT(filter1), "caps", caps1,NULL); g_object_set(G_OBJECT(filter2), "caps", caps2, NULL); g_object_set(G_OBJECT(filter3), "caps", caps3, NULL); g_object_set(G_OBJECT(filter4), "caps", caps4, NULL); g_object_set(G_OBJECT(mux), "batch-size", 1, "live-source", 1, "width", 640, "height", 480, NULL); g_object_set(G_OBJECT(infer),"config-file-path", "/opt/nvidia/deepstream/deepstream-4.0/sources/apps/sample_apps/deepstream-test1/dstest1_pgie_config.txt",NULL ); gchar pad_name_sink[16] = "sink_0"; gchar pad_name_src[16] = "src"; GstPad *src_pad = gst_element_get_static_pad(convert4, pad_name_src); GstPad *sink_pad = gst_element_get_request_pad(mux, pad_name_sink); gst_pad_link(src_pad, sink_pad); gst_object_unref(sink_pad); gst_object_unref(src_pad); gst_bin_add_many(GST_BIN(pipeline), source, filter1,convert1,filter2,convert2,filter3,convert3,filter4, convert4,mux,infer,NULL); gst_element_link_many(source, filter1,convert1, filter2, convert2,filter3, convert3 ,filter4, convert4,NULL); gst_element_link_many(mux, infer,NULL); /* Start playing */ ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); if (ret == GST_STATE_CHANGE_FAILURE) { g_printerr ("Unable to set the pipeline to the playing state.\n"); gst_object_unref (pipeline); return -1; } /* Wait until error or EOS */ bus = gst_element_get_bus (pipeline); msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); /* Parse message */ if (msg != NULL) { GError *err; gchar *debug_info; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_ERROR: gst_message_parse_error (msg, &err, &debug_info); g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message); g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none"); g_clear_error (&err); g_free (debug_info); break; case GST_MESSAGE_EOS: g_print ("End-Of-Stream reached.\n"); break; default: /* We should not reach here because we only asked for ERRORs and EOS */ g_printerr ("Unexpected message received.\n"); break; } gst_message_unref (msg); } /* Free resources */ gst_object_unref (bus); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); return 0; } and I get this (wtf:17982): GLib-GObject-WARNING **: 15:37:43.936: cannot register existing type 'GstInterpolationMethod' (wtf:17982): GLib-GObject-CRITICAL **: 15:37:43.936: g_param_spec_enum: assertion 'G_TYPE_IS_ENUM (enum_type)' failed (wtf:17982): GLib-GObject-CRITICAL **: 15:37:43.937: validate_pspec_to_install: assertion 'G_IS_PARAM_SPEC (pspec)' failed 0:00:00.753282361 17982 0x55ae4f0d60 INFO nvinfer gstnvinfer.cpp:519:gst_nvinfer_logger:<inference> NvDsInferContext[UID 1]:initialize(): Trying to create engine from model files 0:00:26.279690176 17982 0x55ae4f0d60 INFO nvinfer gstnvinfer.cpp:519:gst_nvinfer_logger:<inference> NvDsInferContext[UID 1]:generateTRTModel(): Storing the serialized cuda engine to file at /opt/nvidia/deepstream/deepstream-4.0/samples/models/Primary_Detector/resnet10.caffemodel_b1_int8.engine 0:00:26.388676632 17982 0x55ae4f1b20 WARN v4l2bufferpool gstv4l2bufferpool.c:790:gst_v4l2_buffer_pool_start:<source:pool:src> Uncertain or not enough buffers, enabling copy threshold 0:00:28.620696872 17982 0x55ae4f1b20 WARN basesrc gstbasesrc.c:3055:gst_base_src_loop:<source> error: Internal data stream error. 0:00:28.620764652 17982 0x55ae4f1b20 WARN basesrc gstbasesrc.c:3055:gst_base_src_loop:<source> error: streaming stopped, reason not-linked (-1) Error received from element source: Internal data stream error. Debugging information: gstbasesrc.c(3055): gst_base_src_loop (): /GstPipeline:test_pipeline/GstV4l2Src:source: streaming stopped, reason not-linked (-1) I dont think the pads are linking. I checked their pad template formats and both nvvidconv and nvvideoconvert can have NV12 as their src and nvstreammux has the capability to receive NV12 as sink. I am still debugging. Any help would be appreciated. Thanks!
Sorry it was my fault. I was able to figure out my problem. its in the construction and linking of my pipeline. I was able to set it. And it works well now! Thank you all for the support! #include <gst/gst.h> int main(int argc, char *argv[]) { GstElement *bin, *pipeline, *source, *convert1,*filter1,*convert2,*filter2,*convert3,*filter3,*convert4,*filter4, *muxsink,*infer,*tiler,*osd,*transform,*sink; GstBus *bus; GstCaps *caps1,*caps2,*caps3,*caps4; GstMessage *msg; GstStateChangeReturn ret; gchar *string1 = "video/x-raw(memory:NVMM),format=(string)NV12"; gst_init(&argc, &argv); pipeline = gst_pipeline_new("wtf-pipeline"); bin = gst_bin_new("wtf-bin"); source = gst_element_factory_make("v4l2src", "source"); filter1 = gst_element_factory_make("capsfilter", "filter"); convert1 = gst_element_factory_make("nvvidconv", "convert"); filter2 = gst_element_factory_make("capsfilter", "filter2"); filter3 = gst_element_factory_make("capsfilter", "filter3"); filter4 = gst_element_factory_make("capsfilter", "filter4"); convert3 = gst_element_factory_make("nvvideoconvert", "convert3"); convert2 = gst_element_factory_make("nvvidconv", "convert2"); convert4 = gst_element_factory_make("nvvideoconvert", "convert4"); infer = gst_element_factory_make("nvinfer", "inference"); tiler = gst_element_factory_make("nvmultistreamtiler", "tiler"); osd = gst_element_factory_make("nvdsosd", "osd"); transform = gst_element_factory_make("nvegltransform", "transform"); sink = gst_element_factory_make("nveglglessink", "sink"); muxsink = gst_element_factory_make("nvstreammux", "muxsink"); gst_bin_add_many(GST_BIN(pipeline), source,filter1,convert1,filter2,convert2,filter3,convert4,filter4, muxsink,infer,tiler,convert3,osd,transform,sink, NULL); // gst_bin_add(GST_BIN(pipeline), bin); // source(v4l2src) -> filter1(YUY2)->convert1(nvvidconv)->filter2(memoryNV12)->convert2(nvvidconv) //-->filter3(NV12string)-->convert4(nvvideoconvert)->filter4(memoryNV12)->mux(sink)->infer(nvinfer) //--> tiler(nvmultistreamtiler)->convert3(nvvideoconvert)->osd(nvdsosd)->transform(nvegltransform)->sink(nveglglessink) gst_element_link_many(source,filter1,convert1,filter2, convert2,filter3,convert4,filter4,NULL); caps1 = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING,"YUY2", NULL); caps2 = gst_caps_from_string(string1); caps3 = gst_caps_new_simple("video/x-raw", "format", G_TYPE_STRING, "NV12", NULL); caps4 = gst_caps_from_string(string1); g_object_set(G_OBJECT(filter1), "caps", caps1, NULL); g_object_set(G_OBJECT(filter2), "caps", caps2, NULL); g_object_set(G_OBJECT(filter3), "caps", caps3, NULL); g_object_set(G_OBJECT(filter4), "caps", caps4, NULL); // g_object_set(G_OBJECT(sink), "batch-size", 1, NULL); // g_object_set(G_OBJECT(sink),"width",640,"height",480, "batch-size", 1, "live-source", 1, NULL ); GstPad *source_pad = gst_element_get_static_pad(filter4, "src"); guint i=0; gchar pad_name[16]= {}; g_snprintf(pad_name, 15, "sink_%u",i); GstPad *sink_pad = gst_element_get_request_pad(muxsink,pad_name); g_object_set(G_OBJECT(muxsink),"width",640,"height",480, "batch-size", 1, "live-source", 1, NULL ); gst_pad_link(source_pad, sink_pad); g_object_set(G_OBJECT(infer), "config-file-path", "/opt/nvidia/deepstream/deepstream-4.0/sources/apps/sample_apps/deepstream-test1/dstest1_pgie_config.txt", "batch-size", 1, NULL); g_object_set(G_OBJECT(tiler), "rows", 1, "columns", 1, "width", 640, "height", 480, NULL); gst_element_link_many(muxsink,infer,tiler,convert3,osd,transform,sink,NULL); gst_element_set_state(pipeline, GST_STATE_PLAYING); bus = gst_element_get_bus (pipeline); msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); /* Parse message */ if (msg != NULL) { GError *err; gchar *debug_info; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_ERROR: gst_message_parse_error (msg, &err, &debug_info); g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message); g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none"); g_clear_error (&err); g_free (debug_info); break; case GST_MESSAGE_EOS: g_print ("End-Of-Stream reached.\n"); break; default: /* We should not reach here because we only asked for ERRORs and EOS */ g_printerr ("Unexpected message received.\n"); break; } gst_message_unref (msg); } /* Free resources */ gst_object_unref (bus); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); return 0; }
C++ - Forked Process Can't Read from Shared Memory
I'm learning about process management and shared memory, and I was wondering if someone could help me out. I'm trying to read in a large-ish text file (2MB) with a forked parent process and feed it to the corresponding child process to be ... well ... processed. However, my proof of concept mini program cannot READ the data I write into the shared memory. Calling 'capacity()' and 'length()' work fine, but actually attempting to retrieve the data stored there returns an empty string. I even tried copying the contents from the pointer into an array of characters, but still nothing. Any thoughts? Program code: #include <stdio.h> #include <stdlib.h> #include <string> #include <sys/mman.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> using namespace std; #define SHM_SIZE 2000000 // 2 MB of shared memory int main(int argc, char* argv[]) { string* data = (string*) mmap(NULL, SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); printf("Shared memory capacity before reserve: %ld\n", data->capacity()); data->reserve(SHM_SIZE); // make sure string can use all available space printf("Shared memory capacity after reserve: %ld\n", data->capacity()); switch(fork()) { case -1: printf("Something went wrong ... exiting program\n"); break; case 0: usleep(1000 * 1000 * 2); // force child to wait for sanity purposes printf("\nChild capacity: %ld\n", data->capacity()); printf("Child contents: %s\n", data->c_str()); break; default: // Sample input ... file reading logic omitted for brevity *data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean leo elit, aliquam " "vitae aliquam sed, rhoncus et mi. Aliquam erat volutpat. Phasellus non urna sit amet " "enim tincidunt aliquam quis sit amet orci. Maecenas velit turpis, venenatis eu diam " "vel, varius volutpat nulla. Nam mi massa, tristique eget imperdiet id, dictum ut urna. " "Nulla id massa placerat, finibus purus quis, ornare neque. Vivamus eget varius ante. " "Aenean varius ac neque quis ultricies. Donec vitae bibendum dolor, vitae tempor augue."; printf("\nParent capacity: %ld\n", data->capacity()); printf("Parent contents: %s\n", data->c_str()); wait(NULL); munmap(data, sizeof *data); printf("\nHello world\n"); break; } return 0; } Output: MacBook-Pro:sharedmem-test slehr$ ./sharedmem-mapred Shared memory capacity before reserve: 22 Shared memory capacity after reserve: 2000015 Parent capacity: 2000015 Parent contents: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean leo elit, aliquam vitae aliquam sed, rhoncus et mi. Aliquam erat volutpat. Phasellus non urna sit amet enim tincidunt aliquam quis sit amet orci. Maecenas velit turpis, venenatis eu diam vel, varius volutpat nulla. Nam mi massa, tristique eget imperdiet id, dictum ut urna. Nulla id massa placerat, finibus purus quis, ornare neque. Vivamus eget varius ante. Aenean varius ac neque quis ultricies. Donec vitae bibendum dolor, vitae tempor augue. Child capacity: 2000015 Child contents: Hello world MacBook-Pro:sharedmem-test slehr$
A std::string is likely to be some data structure with a size, a length, a pointer (or something similar). You can't expect its internal pointer to point to shared memory with mmap-ed memory you should use raw pointers, e.g. auto data = (char*) mmap(NULL, SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); Of course you should test against failure: if (data==(char*)MAP_FAILED) { perror("mmap"); exit(EXIT_FAILURE); }; Read again mmap(2) You might consider shm_overview(7) (and look at sem_oveview(7) for synchronization) Read Advanced Linux Programming
How to call postgresql methods from console application VS2015?
I have created a new console application project. I copied source "Example Program 1" from this link. Then I go to "Project properties"->C/C++->General->"Additional Include Directories" and add path "C:\Program Files\PostgreSQL\9.5\include\". Then I go to "Project properties"->Linker->General->"Additional Library Directories" and add path "C:\Program Files\PostgreSQL\9.5\lib". Then I go to "Project properties"->Linker->Input->Additional Dependencies" and add name of the file "libpq.lib". And then I compiled it. 1>------ Сборка начата: проект: ConsoleApplication1, Конфигурация: Debug Win32 ------ 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQconnectdb в функции _main 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQfinish в функции "void __cdecl exit_nicely(struct pg_conn *)" (?exit_nicely##YAXPAUpg_conn###Z) 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQstatus в функции _main 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQerrorMessage в функции _main 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQexec в функции _main 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQresultStatus в функции _main 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQntuples в функции _main 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQnfields в функции _main 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQfname в функции _main 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQgetvalue в функции _main 1>ConsoleApplication1.obj : error LNK2019: ссылка на неразрешенный внешний символ _PQclear в функции _main 1>C:\Users\test\Documents\Visual Studio 2015\Projects\ConsoleApplication1\Debug\ConsoleApplication1.dll : fatal error LNK1120: неразрешенных внешних элементов: 11 ========== Сборка: успешно: 0, с ошибками: 1, без изменений: 0, пропущено: 0 ========== Compiler commands: /GS /analyze- /W3 /Zc:wchar_t /I"C:\Program Files\PostgreSQL\9.5\include\" /ZI /Gm /Od /Fd"Debug\vc140.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /nologo /Fo"Debug\" /Fp"Debug\ConsoleApplication1.pch" Linker commands: /OUT:"C:\Users\test\documents\visual studio 2015\Projects\ConsoleApplication1\Debug\ConsoleApplication1.dll" /MANIFEST /NXCOMPAT /PDB:"C:\Users\test\documents\visual studio 2015\Projects\ConsoleApplication1\Debug\ConsoleApplication1.pdb" /DYNAMICBASE "libpq.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /IMPLIB:"C:\Users\test\documents\visual studio 2015\Projects\ConsoleApplication1\Debug\ConsoleApplication1.lib" /DEBUG /DLL /MACHINE:X86 /INCREMENTAL /PGD:"C:\Users\test\documents\visual studio 2015\Projects\ConsoleApplication1\Debug\ConsoleApplication1.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\ConsoleApplication1.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Program Files\PostgreSQL\9.5\lib" /TLBID:1 What I missed?
Different CRC32 checksum for the same file
Basically, I have an application which imports a few DLLs and some Python libraries. I did another application which calculates CRC32 for each of these files and I've added the list on my main application because I want to make it to check these files. The problem is that sometimes the main application detects a DLL or a library modified even if it wasn't. It don't happens everytime and I am wondering why does that happens? What can determine the CRC32 checksum to differ? It's because my application loads these DLLs or is something external like viruses or anything else? Here's the code for both main application and the application which does the CRC32 list: #include "boost/crc.hpp" #include "boost/filesystem/operations.hpp" #include "boost/filesystem/path.hpp" #include "boost/progress.hpp" #include "boost/integer.hpp" using namespace std; namespace fs = boost::filesystem; int CheckCRC32(LPCSTR szFileName, DWORD dwCRC32) { if (!fs::exists(szFileName)) return 1; DWORD dwResult = 0; boost::crc_32_type result; std::streamsize const buffer_size = 1024; ifstream file(szFileName, std::ios_base::binary); if (file) { do { char buffer[buffer_size]; file.read(buffer, buffer_size); result.process_bytes(buffer, file.gcount()); } while(file); } else return 1; dwResult = result.checksum(); if (dwResult <= 0) return 1; if (dwResult != dwCRC32) return 2; return 0; } Also, if you have another solution for doing such things or if you have a solution for this method, please let me know.
I am not really trusting your 1024 bytes fixed buffer and the order of calls you chose. Either it is your intention to only use the first 1024 bytes of your files for the crc or this could already be the problem. On the other hand, if the files you crc are smaller than those 1024, it is up to the behavior of file.read() what happens. Just to give you an option, here the code for a "low level" alternative. If the same crc values will be obtained with this version will depend on whether my initial crc value of 0 is "by the book" or if you need to use another start value. #include <Windows.h> #include <cstdint> #include <string> #include <vector> static uint32_t crc32_tab[] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; uint32_t crc32(uint32_t crc, const void *buf, size_t size) { const uint8_t *p = static_cast<const uint8_t*>(buf); crc = crc ^ ~0U; while (size--) crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); return crc ^ ~0U; } bool Crc32OfFile(const char * pathToFile, uint32_t &result) { bool success = false; HANDLE hFile = ::CreateFileA ( pathToFile , GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN , NULL ); if (INVALID_HANDLE_VALUE != hFile) { DWORD fileSize = ::GetFileSize(hFile, NULL); std::vector<uint8_t> buffer; buffer.resize(fileSize); DWORD bytesRead = 0UL; if (::ReadFile(hFile, &buffer[0], buffer.size(), &bytesRead, NULL)) { if (bytesRead == fileSize) { result = crc32(0UL, &buffer[0], buffer.size()); success = true; } } ::CloseHandle(hFile); } return success; }
IXMLDOMDocument::selectNodes doesn't work as expected
It's amazing IXMLDOMDocument::selectNodes doesn't work as expected. I know it's because xmlns="http://stackoverflow.com/questions/ask", but I don't know how to make it work if xmlns is present. V_BSTR(&varParam) = SysAllocString(LR"iPhone5s(XPath)iPhone5s"); V_VT(&varParam) = VT_BSTR; hr = ptrXMLDom->setProperty(L"SelectionLanguage", varParam); ptrXMLDom->selectNodes(L"//bookstore", &ptrDomNodeList); ptrDomNodeList->get_length(&len);//the value is always 0 Remarks: the xml is read-only. Don't tell me to modify original XML. Here is my code: #include <msxml6.h> #include <msxml2.h>//necessary in Visual Studio 2013 HRESULT hr = CoInitialize(NULL); HRESULT hr = CoCreateInstance(__uuidof(DOMDocument60), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(ppDoc)); if (SUCCEEDED(hr)) { // these methods should not fail so don't inspect result (*ppDoc)->put_async(VARIANT_FALSE); (*ppDoc)->put_validateOnParse(VARIANT_FALSE); (*ppDoc)->put_resolveExternals(VARIANT_FALSE); (*ppDoc)->put_preserveWhiteSpace(VARIANT_TRUE); } HRESULT hr = S_OK; IXMLDOMDocument2 *ptrXMLDom = NULL; VARIANT_BOOL varBool = VARIANT_FALSE; BSTR bstrXML = nullptr; VARIANT varParam; VariantInit(&varParam); V_BSTR(&varParam) = SysAllocString(LR"iPhone5s(E:\Work\book.xml)iPhone5s"); V_VT(&varParam) = VT_BSTR; hr = ptrXMLDom->load(varParam, &varBool); V_BSTR(&varParam) = SysAllocString(LR"iPhone5s(XPath)iPhone5s"); V_VT(&varParam) = VT_BSTR; hr = ptrXMLDom->setProperty(L"SelectionLanguage", varParam); ptrXMLDom->selectNodes(L"//bookstore", &ptrDomNodeList); ptrDomNodeList->get_length(&len);//the value is always 0 CoUninitialize(); Here is the xml: <?xml version="1.0" encoding="ISO-8859-1"?> <!-- Copyright w3school.com.cn --> <!-- W3School.com.cn bookstore example --> <bookstore xmlns="http://stackoverflow.com/questions/ask" version="1.0"> <book category="children"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="cooking"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="web" cover="paperback"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> <book category="web"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book> </bookstore>
i have found the answer by myself. V_BSTR(&varParam) = SysAllocString(LR"iPhone5s(xmlns:pf='http://stackoverflow.com/questions/ask')iPhone5s"); V_VT(&varParam) = VT_BSTR; hr = ptrXMLDom->setProperty(L"SelectionNamespaces", varParam); ptrXMLDom->selectNodes(L"//pf:bookstore/pf:book", &ptrDomNodeList); ptrDomNodeList->get_length(&len);//4