如何将宏函数从DLL导出到另一个DLL? [英] How to export macro function from DLL to another DLL?

查看:124
本文介绍了如何将宏函数从DLL导出到另一个DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个灵魂项目,在主要灵魂中,我必须使用我的logger dll文件另一个dll,如何将此文件导出到另一个dll?请帮帮我。

ProjectA

---------------

Simple_logger.h

I have 3 soultions projects,inside main soultion,i have to use my logger dll file another dll,how to export this file to another dll?please help me.
ProjectA
---------------
Simple_logger.h

#pragma once
#include<crtdefs.h>
#include<boost/log/expressions.hpp>
#include<boost/log/expressions/formatters/named_scope.hpp>
#include<boost/log/sources/global_logger_storage.hpp>
#include<boost/log/support/date_time.hpp>
#include<boost/log/trivial.hpp>
#include<boost/log/utility/setup.hpp>
#include<string.h>
#include"Binary_Export.h"

#include <boost/log/sinks/debug_output_backend.hpp>
#define FILE (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define  INFO  BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::info) << "|" << FILE<< "| " <<" "<<"|"<< __LINE__ << "| "<<__FUNCSIG__

#define WARN  BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::warning) <<  "|" << FILE<< "| " <<" "<<"|"<< __LINE__ << "| "<<__FUNCSIG__
#define ERROR BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::error) <<  "|" << FILE<< "| " <<" "<<"|"<< __LINE__ << "| "<<__FUNCSIG__

#define SYS_LOGFILE   "C:\\Users\\janardhanreddyn\\Documents\\LogFile\\Logfile.log"

//Narrow-char thread-safe logger.
typedef boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level> logger_t;
 
//declares a global logger with a custom initialization
 BOOST_LOG_GLOBAL_LOGGER(my_logger, logger_t)








Simple Logger.cpp

---------- ----------








Simple Logger.cpp
--------------------


#include"Simple_Logger.h"
namespace logging = boost::log;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;
//Defines a global logger initialization routine
BOOST_LOG_GLOBAL_LOGGER_INIT(my_logger, logger_t)
{
	logger_t lg;

	logging::add_common_attributes();

	logging::add_file_log(
		keywords::file_name = SYS_LOGFILE,
		keywords::rotation_size = 1024 * 1024 * 20,    // megabytes
		keywords::time_based_rotation = boost::log::sinks::file::rotation_at_time_point (0, 0, 0),
		keywords::auto_flush = true,
		keywords::format = (
		expr::stream<<expr::format_date_time <boost::posix_time::ptime> ("TimeStamp", "%d-%m-%y %H:%M:%S")
		<< " [" << expr::attr <boost::log::trivial::severity_level> ("Severity") << "]: "
		<< expr::smessage

		)
		);

	logging::add_console_log(
		std::cout,
		keywords::format = (
		expr::stream <<"|"<< expr::format_date_time <boost::posix_time::ptime> ("TimeStamp", "%d-%m-%y %H:%M:%S")<<"|"
		<< " [" << expr::attr <boost::log::trivial::severity_level> ("Severity") << "]: "
		<< expr::smessage

		)

		);

	logging::core::get()->set_filter
		(
		logging::trivial::severity >= logging::trivial::info
		);

	return lg;
}





我的尝试:



另一个项目B

----------------------

Factory.h

=============



What I have tried:

another Project B
----------------------
Factory.h
=============

#pragma once
#include"tfexports.h"
#include"Simple_Logger.h"

#include<iostream>
class TF_API AFactory
{

public:
	 AFactory();
	 ~AFactory();
	  virtual void Func();


};







factory.cpp

==============






factory.cpp
==============

#include"Factory.h"


AFactory::AFactory()
{

	INFO<<"AFactory Constructor";
}
AFactory::~AFactory()
{


}
void AFactory::Func()
{


	<pre>INFO<<"AFactory Constructor";



}





当我使用INFO时,只生成.DLL文件,生成.lib文件,生成.lib文件,我必须将一些宏导出到另一个dll,但我不知道怎么办。


}


when i used INFO ,only .DLL file generated,.lib file not generated,for generating .lib file,i have to export some macros to another dll, but i dont know ,how to do.

推荐答案

理查德是对的 CANT 导出宏。宏在构建过程的第一步中解析为代码。



考虑:



a)导出具有所有必需参数的函数。

b)直接复制一些额外文件中的代码进入另一个项目。



我会使用解决方案b)但是这些方法的某些组合可以满足您的需求。
Richard is right you CANT export macros. Macros get resolved to code in the first step of the build process.

Consider:

a) exporting functions with all needed parameters.
b) directly copy the code into the other project in some extra files.

I would use solution b) but maybe some mix of these approaches will suite your needs.

< br>

Quote:

如何将宏函数从DLL导出到另一个DLL?

How to export macro function from DLL to another DLL?



你没有,DLL是一个黑盒子,你不能在DLL之间移动东西。



注意C ++宏不在DLL中,它们是指令对于构建DLL的编译器,它们不会进入DLL。



您需要从源代码中复制宏。


You don't, DLL is a black box, you can't move things between DLLs.

Note that C++ macros are not in the DLLs, they are directives for the compiler which build the DLLs and they don't make their way to the DLLs.

You need to copy macros from source code.


这篇关于如何将宏函数从DLL导出到另一个DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆