Use VS + VisualGDB to compile Linux RCF and visualgdbrcf

Source: Internet
Author: User

Use VS + VisualGDB to compile Linux RCF and visualgdbrcf

As mentioned in the RCF introduction, RCF supports cross-platform communication and its code can be compiled on the Linux platform through tools such as gcc and make.

In the official source code, only the cmake compiling script is provided, and no Makefile is provided. If you want to use make to compile the script directly, you must write the Makefile yourself.

Aside from that, this article mainly describes how to compile and debug the RCF library of Linux Through VS and VisualGDB on Windows systems.

Using VS + VisualGDB to compile and debug Linux programs, this article has briefly introduced the usage of VisualGDB. This article goes straight to the topic and introduces the compiling method of RCF static library.

Configure a project through the wizard

When creating a project through the wizard, the following are the important steps,

Select static library as the project type:

Mount. cifs // 192.168.3.125/rcf. linux '/code/rcf'-o user = hbccdf, pass = '***', nopermConfigure directory structure

The configured directory structure is as follows:

D:\CODE\C++\RCF.LINUX├─Debug├─include│  ├─RCF│  │  ├─external│  │  │  └─asio│  │  │      └─asio│  │  │          ├─detail│  │  │          │  └─impl│  │  │          ├─impl│  │  │          ├─ip│  │  │          │  ├─detail│  │  │          │  │  └─impl│  │  │          │  └─impl│  │  │          ├─local│  │  │          │  └─detail│  │  │          │      └─impl│  │  │          ├─posix│  │  │          ├─ssl│  │  │          │  └─detail│  │  │          └─windows│  │  ├─test│  │  ├─thread│  │  │  └─impl│  │  ├─utf8│  │  │  └─detail│  │  └─util│  │      └─Platform│  │          └─OS│  │              ├─Unix│  │              └─Windows│  └─SF├─rcf.linux│  ├─Debug│  │  └─rcf.linux.tlog│  ├─obj│  │  └─Win32│  │      └─Debug│  └─VisualGDBCache│      └─rcf.linux-Debug└─src    ├─RCF    │  ├─test    │  └─util    └─SF
Modify project configuration

You can use visual GDB to modify project configurations, that is, Makefile configurations. You can also use VS to directly modify text content:

1> ------ generated: Project: rcf. in linux, configure: Debug Win32 ------ 1> VisualGDB: Testing shared folder-based mapping D: \ Code \ C ++ \ rcf. linux \ rcf. linux <=> 192.168.3.128:/code/rcf. linux... 1> VisualGDB: Trying to create D: \ Code \ C ++ \ rcf. linux \ rcf. linux \ vgdb1889774204.tmp... 1> VisualGDB: Run "make CONFIG = Debug" in directory "/code/rcf. linux on root@192.168.3.128 (SSH) 1> g ++-ggdb-ffunction-sections-O0-I .. /include-DDEBUG-c .. /src/RCF. cpp-o Debug/RCF. o-MD-MF Debug/RCF. dep1> ar-r Debug/librcf. a Debug/RCF. o1> ar: creating Debug/librcf. a ============ generate: 1 successful, 0 failed, 0 latest, skipped 0 ===========Add Test Program

Use the visual GDB Wizard to add the test program rcftest,

Then configure the project:

# Pragma once # include "rcf/rcf. hpp "# include <iostream> # include <string> using namespace std; RCF_BEGIN (I _HELLO," I _HELLO ") RCF_METHOD_V1 (void, SayHello, const string &) RCF_METHOD_R1 (int, add, add, int &) RCF_METHOD_V0 (void, test) RCF_END (I _HELLO) class HelloImpl {public: void SayHello (const string & world) {cout <"hello" <world <endl;} int add (int & a) {a = a + a; return a + 2;} void test () {}};

Then add the test code:

# Include <iostream> # include "hello. h "using namespace std; int main (int argc, char * argv []) {RCF: RcfInitDeinit rcf_init; HelloImpl hello; RCF: RcfServer server (RCF :: tcpEndpoint (50001); server. bind <I _HELLO> (hello); server. start (); RcfClient <I _HELLO> client (RCF: TcpEndpoint (50001); string str = "test"; client. sayHello (str); int a = 3; int B = client. add (a); cout <"a =" <a <", B =" <B <endl; for (int I = 0; I <20000; ++ I) {client. test () ;}cout <"finished" <endl ;}

The following is the compilation information:

1> ------ generated: Project: rcftest, configuration: Debug Win32 ------ 1> VisualGDB: Testing shared folder-based mapping D: \ Code \ C ++ \ rcf. linux \ rcftest <=> 192.168.3.128:/code/rcf/rcftest... 1> VisualGDB: Trying to create D: \ Code \ C ++ \ rcf. linux \ rcftest \ vgdb1568095730.tmp... 1> Updating D: \ Code \ C ++ \ rcf. linux \ rcftest \ Makefile1> VisualGDB: Updated source file list in D: \ Code \ C ++ \ rcf. linux \ rcftest \ Makefile. enable verbose mode for more details.1> VisualGDB: Run "make CONFIG = Debug" in directory "/code/rcf/rcftest" on root@192.168.3.128 (SSH) 1> g ++-ggdb-ffunction-sections-O0-I .. /include-DDEBUG-c rcftest. cpp-o Debug/rcftest. o-MD-MF Debug/rcftest. dep1> g ++-o Debug/rcftest-Wl,-gc-sections-L .. /rcf. linux/Debug-Wl, -- start-group Debug/rcftest. o-lrcf-lpthread-ldl-Wl, -- rpath = '$ origin'-Wl, -- end-group ========== generated: 1 success, 0 failed, latest 0, skipped 0 ==========
Run the test program and view the test results

You can debug and run VS F5 to view the running result:

# Generated by VisualGDB (http://visualgdb.com) # do not edit this file manually unless you absolutely need to # use visualgdb project properties dialog insteadbinarydir: = Debug # ToolchainCC: = gccCXX: = g ++ LD :=$ (CXX) AR: = arOBJCOPY: = objcopy # Additional flagsPREPROCESSOR_MACROS: = DEBUGINCLUDE_DIRS: = .. /outputs: = LIBRARY_NAMES: = volumes: = MACOS_FRAMEWORKS: = LINUX_PACKAGES: = CFLAGS: =-ggdb-ffunction-sections-O0CXXFLAGS: =-ggdb-ffunction-sections-O0ASFLAGS: = LDFLAGS: =-Wl,-gc-sectionsCOMMONFLAGS: = START_GROUP: =-Wl, -- start-groupEND_GROUP: =-Wl, -- end-group # Additional options detected from testing the toolchainIS_LINUX_PROJECT: = 1

Makefile file:

#Generated by VisualGDB project wizard. #Note: VisualGDB will automatically update this file when you add new sources to the project.#All other changes you make in this file will be preserved.#Visit http://visualgdb.com/makefiles for more details#VisualGDB: AutoSourceFiles        #<--- remove this line to disable auto-updating of SOURCEFILES and EXTERNAL_LIBSTARGETNAME := librcf.a#TARGETTYPE can be APP, STATIC or SHAREDTARGETTYPE := STATICto_lowercase = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))CONFIG ?= DEBUGCONFIGURATION_FLAGS_FILE := $(call to_lowercase,$(CONFIG)).makinclude $(CONFIGURATION_FLAGS_FILE)include $(ADDITIONAL_MAKE_FILES)ifeq ($(BINARYDIR),)error:    $(error Invalid configuration, please check your inputs)endifSOURCEFILES := ../src/RCF/RCF.cppEXTERNAL_LIBS := EXTERNAL_LIBS_COPIED := $(foreach lib, $(EXTERNAL_LIBS),$(BINARYDIR)/$(notdir $(lib)))CFLAGS += $(COMMONFLAGS)CXXFLAGS += $(COMMONFLAGS)ASFLAGS += $(COMMONFLAGS)LDFLAGS += $(COMMONFLAGS)CFLAGS += $(addprefix -I,$(INCLUDE_DIRS))CXXFLAGS += $(addprefix -I,$(INCLUDE_DIRS))CFLAGS += $(addprefix -D,$(PREPROCESSOR_MACROS))CXXFLAGS += $(addprefix -D,$(PREPROCESSOR_MACROS))ASFLAGS += $(addprefix -D,$(PREPROCESSOR_MACROS))CXXFLAGS += $(addprefix -framework ,$(MACOS_FRAMEWORKS))CFLAGS += $(addprefix -framework ,$(MACOS_FRAMEWORKS))LDFLAGS += $(addprefix -framework ,$(MACOS_FRAMEWORKS))LDFLAGS += $(addprefix -L,$(LIBRARY_DIRS))ifeq ($(GENERATE_MAP_FILE),1)LDFLAGS += -Wl,-Map=$(BINARYDIR)/$(basename $(TARGETNAME)).mapendifLIBRARY_LDFLAGS = $(addprefix -l,$(LIBRARY_NAMES))ifeq ($(IS_LINUX_PROJECT),1)    RPATH_PREFIX := -Wl,--rpath='$$ORIGIN/../    LIBRARY_LDFLAGS += $(EXTERNAL_LIBS)    LIBRARY_LDFLAGS += -Wl,--rpath='$$ORIGIN'    LIBRARY_LDFLAGS += $(addsuffix ',$(addprefix $(RPATH_PREFIX),$(dir $(EXTERNAL_LIBS))))        ifeq ($(TARGETTYPE),SHARED)        CFLAGS += -fPIC        CXXFLAGS += -fPIC        ASFLAGS += -fPIC        LIBRARY_LDFLAGS += -Wl,-soname,$(TARGETNAME)    endif        ifneq ($(LINUX_PACKAGES),)        PACKAGE_CFLAGS := $(foreach pkg,$(LINUX_PACKAGES),$(shell pkg-config --cflags $(pkg)))        PACKAGE_LDFLAGS := $(foreach pkg,$(LINUX_PACKAGES),$(shell pkg-config --libs $(pkg)))        CFLAGS += $(PACKAGE_CFLAGS)        CXXFLAGS += $(PACKAGE_CFLAGS)        LIBRARY_LDFLAGS += $(PACKAGE_LDFLAGS)    endif    else    LIBRARY_LDFLAGS += $(EXTERNAL_LIBS)endifLIBRARY_LDFLAGS += $(ADDITIONAL_LINKER_INPUTS)all_make_files := $(firstword $(MAKEFILE_LIST)) $(CONFIGURATION_FLAGS_FILE) $(ADDITIONAL_MAKE_FILES)ifeq ($(STARTUPFILES),)    all_source_files := $(SOURCEFILES)else    all_source_files := $(STARTUPFILES) $(filter-out $(STARTUPFILES),$(SOURCEFILES))endifsource_obj1 := $(all_source_files:.cpp=.o)source_obj2 := $(source_obj1:.c=.o)source_obj3 := $(source_obj2:.s=.o)source_obj4 := $(source_obj3:.S=.o)source_obj5 := $(source_obj4:.cc=.o)source_objs := $(source_obj5:.cxx=.o)all_objs := $(addprefix $(BINARYDIR)/, $(notdir $(source_objs)))PRIMARY_OUTPUTS :=ifeq ($(GENERATE_BIN_FILE),1)PRIMARY_OUTPUTS += $(BINARYDIR)/$(basename $(TARGETNAME)).binendififeq ($(GENERATE_IHEX_FILE),1)PRIMARY_OUTPUTS += $(BINARYDIR)/$(basename $(TARGETNAME)).ihexendififeq ($(PRIMARY_OUTPUTS),)PRIMARY_OUTPUTS := $(BINARYDIR)/$(TARGETNAME)endifall: $(PRIMARY_OUTPUTS)$(BINARYDIR)/$(basename $(TARGETNAME)).bin: $(BINARYDIR)/$(TARGETNAME)    $(OBJCOPY) -O binary $< $@$(BINARYDIR)/$(basename $(TARGETNAME)).ihex: $(BINARYDIR)/$(TARGETNAME)    $(OBJCOPY) -O ihex $< $@ifeq ($(TARGETTYPE),APP)$(BINARYDIR)/$(TARGETNAME): $(all_objs) $(EXTERNAL_LIBS)    $(LD) -o $@ $(LDFLAGS) $(START_GROUP) $(all_objs) $(LIBRARY_LDFLAGS) $(END_GROUP)endififeq ($(TARGETTYPE),SHARED)$(BINARYDIR)/$(TARGETNAME): $(all_objs) $(EXTERNAL_LIBS)    $(LD) -shared -o $@ $(LDFLAGS) $(START_GROUP) $(all_objs) $(LIBRARY_LDFLAGS) $(END_GROUP)endif    ifeq ($(TARGETTYPE),STATIC)$(BINARYDIR)/$(TARGETNAME): $(all_objs)    $(AR) -r $@ $^endif-include $(all_objs:.o=.dep)clean:ifeq ($(USE_DEL_TO_CLEAN),1)    del /S /Q $(BINARYDIR)else    rm -rf $(BINARYDIR)endif$(BINARYDIR):    mkdir $(BINARYDIR)#VisualGDB: FileSpecificTemplates        #<--- VisualGDB will use the following lines to define rules for source files in subdirectories$(BINARYDIR)/%.o : %.cpp $(all_make_files) |$(BINARYDIR)    $(CXX) $(CXXFLAGS) -c $< -o $@ -MD -MF $(@:.o=.dep)$(BINARYDIR)/%.o : %.c $(all_make_files) |$(BINARYDIR)    $(CC) $(CFLAGS) -c $< -o $@ -MD -MF $(@:.o=.dep)$(BINARYDIR)/%.o : %.S $(all_make_files) |$(BINARYDIR)    $(CC) $(CFLAGS) $(ASFLAGS) -c $< -o $@ -MD -MF $(@:.o=.dep)$(BINARYDIR)/%.o : %.s $(all_make_files) |$(BINARYDIR)    $(CC) $(CFLAGS) $(ASFLAGS) -c $< -o $@ -MD -MF $(@:.o=.dep)$(BINARYDIR)/%.o : %.cc $(all_make_files) |$(BINARYDIR)    $(CC) $(CFLAGS) $(CXXFLAGS) -c $< -o $@ -MD -MF $(@:.o=.dep)$(BINARYDIR)/%.o : %.cxx $(all_make_files) |$(BINARYDIR)    $(CC) $(CFLAGS) $(CXXFLAGS) -c $< -o $@ -MD -MF $(@:.o=.dep)#VisualGDB: GeneratedRules                #<--- All lines below are auto-generated$(BINARYDIR)/RCF.o : ../src/RCF/RCF.cpp $(all_make_files) |$(BINARYDIR)    $(CXX) $(CXXFLAGS) -c $< -o $@ -MD -MF $(@:.o=.dep)

Rcftest project:

#Generated by VisualGDB (http://visualgdb.com)#DO NOT EDIT THIS FILE MANUALLY UNLESS YOU ABSOLUTELY NEED TO#USE VISUALGDB PROJECT PROPERTIES DIALOG INSTEADBINARYDIR := Debug#ToolchainCC := gccCXX := g++LD := $(CXX)AR := arOBJCOPY := objcopy#Additional flagsPREPROCESSOR_MACROS := DEBUGINCLUDE_DIRS := ../includeLIBRARY_DIRS := ../rcf.linux/DebugLIBRARY_NAMES := rcf pthread dlADDITIONAL_LINKER_INPUTS := MACOS_FRAMEWORKS := LINUX_PACKAGES := CFLAGS := -ggdb -ffunction-sections -O0CXXFLAGS := -ggdb -ffunction-sections -O0ASFLAGS := LDFLAGS := -Wl,-gc-sectionsCOMMONFLAGS := START_GROUP := -Wl,--start-groupEND_GROUP := -Wl,--end-group#Additional options detected from testing the toolchainIS_LINUX_PROJECT := 1

Makefile file:

The Makefile file of the rcf. linux project is basically the same, so it is not listed here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.